fbraem wrote:You can always write your own handler and use that with JSON::Parser instead of the default handler. It's not possible to do this in a generic way, because the parser never knows which types are used in a JSON array. But if you know where these arrays with all integers are, you can handle it differently in your handler.
That is actually what I am trying to do. I guess the best way to serialize data this way would be to also include type marker so that proper type can be instantiated during parsing. But then again that is not how DynamicStruct gets serialized to JSON. My general problem is this:
I have a hierarchy of classes that have a pair of methods:
Code: Select all
void fromJson(const JSONNode&);
JSONNode is an JSON value representation from libjson library, semantically closest to Poco::JSON::Object. It is being used for both serialization and Memento pattern for example for undo actions (state of object it stored in JSONNode in memory then later state is restored from it when needed). Thing is I never really liked this solution, it works but I never wanted it to be this closely tight to JSON. DynamicStruct is perfect replacement imho as it is generic enough and might as well be "visited" by XML serializer. My code already has Any (more or less Dynamic::Any) and DynamicStruct, but finding it in Poco with JSON support already in just raised my hopes for possibility of finally getting rid of libjson (which is crap).