typescript-json-serializer
typescript-json-serializer copied to clipboard
feat: add auto prediction of child class
When dealing with class inheritance in typescript, it is a good idea to store the class name as a field (e.g. __class__
) in the json object when serializing and inspect this field when deserializing it. We can add a JsonObject
option named autoPredicate
in the base class to let the user decide whether to use this feature. You can see auto-predicate.spec.ts
for its usage.
I have implemented a prototype of this feature, it does not have any side effects on existing functions. I hope that you add this function by merging this PR or implementing this yourself referring to my code. Thanks~
BTW, I have also renamed setJsonObject
to setJsonObjectMetadata
to match the getJsonObjectMetadata
function.