Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse json into specified descendant class #3656

Closed
vmato opened this issue Jul 1, 2022 · 3 comments
Closed

Parse json into specified descendant class #3656

vmato opened this issue Jul 1, 2022 · 3 comments
Assignees

Comments

@vmato
Copy link

vmato commented Jul 1, 2022

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

@aleks-f
Copy link
Member

aleks-f commented Jul 4, 2022

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 aleks-f self-assigned this Jul 4, 2022
@aleks-f aleks-f added this to the Release 1.13.0 milestone Jul 4, 2022
@github-actions
Copy link

github-actions bot commented Jul 5, 2023

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

@github-actions github-actions bot added the stale label Jul 5, 2023
@github-actions
Copy link

github-actions bot commented Sep 4, 2023

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

@github-actions github-actions bot closed this as completed Sep 4, 2023
@aleks-f aleks-f removed the stale label Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants