Skip to content

Any.get() method query #35

Description

@anmol27katyani

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions