poco icon indicating copy to clipboard operation
poco copied to clipboard

Parse json into specified descendant class

Open vmato opened this issue 3 years ago • 1 comments

Is it possible to parse json into specified descendant class?

std::string json = "{ \"name\" : \"Franky\" }"

class Person : Poco::JSON::Object {
// ...
}

Person p = ???(json);

I've seen handlers but didn't find any explicit way to override JSON::Object creation

vmato avatar Jul 01 '22 07:07 vmato

You "override" JSON::Object creation by implementing your PersonHandler::asVar() to return a Dynamic::Var which can be converted to Person.

As things stand now, it is doable, but not in an optimal way because ParseHandler::setValue() is private and so the whole handler should be reimplemented. We'll make it protected for 1.13

aleks-f avatar Jul 04 '22 19:07 aleks-f

This issue is stale because it has been open for 365 days with no activity.

github-actions[bot] avatar Jul 05 '23 02:07 github-actions[bot]

This issue was closed because it has been inactive for 60 days since being marked as stale.

github-actions[bot] avatar Sep 04 '23 02:09 github-actions[bot]