Despite the docs says that encode should return false
for anything that isn’t
an instance of the type, returning falsy value, including 0
, will not encode
the type.
Each transporter contains an encode function, which encodes values on the server (or returns false for anything that isn’t an instance of the type) and a corresponding decode function
We have a custom Role
class (src/lib/role.js
). We have define transport
hooks (src/hooks.js
), where it just return number representation of Role
.
However, if the number is 0
, sveltekit throws cannot stringify arbitrary
non-POJOs.
Error: Data returned from `load` while rendering / is not serializable: Cannot
stringify arbitrary non-POJOs (data.role)
npm run dev