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

Any.get() method query #35

Open
anmol27katyani opened this issue Sep 5, 2017 · 2 comments
Open

Any.get() method query #35

anmol27katyani opened this issue Sep 5, 2017 · 2 comments

Comments

@anmol27katyani
Copy link

anmol27katyani commented Sep 5, 2017

Currently, Any API returns .get(...) calls with default values if the specified JSON path does not exist. Consider:

String input = '{ "id": 35, "name": "Agatha", "surname": "Christie" }';
Any any = JsonIterator.deserialize(input);
System.out.println(any.get("age").toInt()); --> prints "0"
Instead of returning some default values ("" for String, 0 for int, etc.), do you think it's sane to have the .get method like this?

Any.get(Object defaultValue, Object... keys)
So we could do this:

String input = '{ "id": 35, "name": "Agatha", "surname": "Christie" }'; Any any = JsonIterator.deserialize(input); System.out.println(any.get(26, "age").toInt()); --> Since "age" key doesn't exist, will print 26

@sumulige
Copy link

any.get("age",26)?

@soumya140602
Copy link

if it is not yet solved then can I do on this??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants