You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Activity
sumulige commentedon Nov 19, 2017
any.get("age",26)?
soumya140602 commentedon Jan 15, 2022
if it is not yet solved then can I do on this??