Builtin (undefined) types are serialized as null. This works well:
> (Int but JSON::Class).to-json
null
> (Str but JSON::Class).to-json
null
> (Int but JSON::Class).from-json: (Int but JSON::Class).to-json;
(Int+{Class})
Custom classes should be serialized the same way. Instead, they're serialized the same way as a defined class, and this either causes round-trip conversion failure, or an exception, depending on whether the class has members:
> class C does JSON::Class { }
> C.to-json;
{
}
> C.from-json: C.to-json;
C.new
> class D does JSON::Class { has $.i; }
> D.to-json;
Cannot look up attributes in a D type object
in block at D:\rakudo-2017.12\share\perl6\site\sources\0D5D5ABC9DC9B8DB1F75571789AD2F8F5FD3487A (JSON::Marshal) line 143
in sub _marshal at D:\rakudo-2017.12\share\perl6\site\sources\0D5D5ABC9DC9B8DB1F75571789AD2F8F5FD3487A (JSON::Marshal) line 132
in sub marshal at D:\rakudo-2017.12\share\perl6\site\sources\0D5D5ABC9DC9B8DB1F75571789AD2F8F5FD3487A (JSON::Marshal) line 172
in method to-json at D:\rakudo-2017.12\share\perl6\site\sources\AEC54816C1D35CBEB0033396AD685FA76A800D6E (JSON::Class) line 94
in block <unit> at <unknown file> line 1
Builtin (undefined) types are serialized as null. This works well:
Custom classes should be serialized the same way. Instead, they're serialized the same way as a defined class, and this either causes round-trip conversion failure, or an exception, depending on whether the class has members: