Issue Details (XML | Word | Printable)

Key: JSONP-10
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: eric.jain
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
jsonp

JsonValue.MISSING

Created: 26/Apr/13 06:39 PM   Updated: 26/Apr/13 06:39 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

Tags:
Participants: eric.jain


 Description  « Hide

Given the following JSON:

{ 
    "settings" : {
        "dashboard" : { 
            "width" : 42
        }
    }
}

This code extracts the value of the width property:

int width = 0;
JsonObject settings = value.getJsonObject("settings");
if (settings != null) {
    JsonObject dashboard = settings.getJsonObject("dashboard");
    if (dashboard != null) {
        width = dashboard.getInt("width", 0)
    }
}

It would be nice if this could be accomplished in a more concise manner, e.g.

int width = value.findJsonObject("settings").findJsonObject("dashboard").getInt("width", 0)

The findJsonObject would behave like getJsonObject, but return an empty JsonObject instead of null for missing properties.



There are no comments yet on this issue.