I am looking for a JSON unmarshaller, that takes the JSON string and apply it to the object (and not take an object and try to apply the JSON to it).

I am looking for a JSON unmarshaller, that takes the JSON string and apply it to the object (and not take an object and try to apply the JSON to it).

Example: SuperObject (https://github.com/hgourvest/superobject) when unmarshalling, it iterates over the object/record fields and tries to apply the JSON to it. This is a problem if the type you unmarshalling to is a descendant of TInterfaceObject, as there is the FRefCount field

What I would like:
* an unmarshaller that iterates through the JSON, and searches the object/record for the field (which could be annotated with the JSON field that it handles), and
* an [Ignore] attribute, so if there isn't a field for that JSON field isn't handled, it will be skipped (and not error out), and
* an attribute to say what a concrete object to use (that way, the field could be an interface, but you can specify the TObject that implements the interface and it knows how to handle it).

Does anyone know if this unarshaller exists in Delphi? or am I asking too much (or just don't understand unmarshalling)?

Comments

  1. I don't think there is an existing solution to this but it should be easy enough to implement this - here is some quick and dirty code to give you the idea (using JsonDataObjects by Andreas Hausladen): https://bitbucket.org/snippets/sglienke/6oBqMb

    ReplyDelete
  2. Stefan Glienke Thanks for the q&d - definitely on the right direction :-)

    ReplyDelete

Post a Comment