Open jasongerbes opened 1 year ago
Hey @jasongerbes! registerClass
and registerCustom
aren't documented well, I agree. If you want to open a PR that adds docs for that, i'd be happy to review it!
Regarding the CustomMap
case, I don't see an easy way of leveraging SuperJSON's built-in Map transformer, either. registerCustom
is probably the best choice. You could try to make a Map
out of your CustomMap
and then recursively call SuperJSON.serialize(v)
inside of serialize
. Would that help?
The superjson README provides a recipe for registering a custom transformer for a non-default data type:
However, the docs don't include any details about the
registerClass
andregisterSymbol
methods, nor do they include details about how a custom transformer can leverage the built-in transformers.For example, given a
CustomMap
class the extends the built-inMap
class and adds acustomProperty
and overriddenget
method, how can I useregisterClass
orregisterCustom
in a way that leverages the built-in serialization of the Map's entires?Using
registerClass(CustomMap)
doesn't serialize theCustomMap
entries:Using
registerCustom
, it's unclear how you can leverage SuperJson's built-in Map transformer to serialize and deserialize theCustomMap
class: