Issue Details (XML | Word | Printable)

Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: jfuerth
Votes: 0
Watchers: 0

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

Shorten getter method names; make chained getters read well when used together

Created: 06/Feb/13 04:06 PM   Updated: 10/Feb/13 06:49 AM   Resolved: 10/Feb/13 06:49 AM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.0-pfd

Time Tracking:
Not Specified

Participants: jfuerth and jitu

 Description  « Hide

The idea here is to make the following two changes, which work well together:

1. Remove 'value' from most getter names
2. Use the same method naming convention on JsonNumber as is used on java.lang.Number

The result is that repetitive-looking use cases like jsonObject.getNumberValue("num").getDoubleValue() turn into this non-repetitive arrangement: jsonObject.getNumber("num").doubleValue().

This suggestion, along with JSON_PROCESSING_SPEC-53, has been implemented here:

jitu added a comment - 08/Feb/13 11:59 PM
  • Your changes have this : JsonParser#getInt(), JsonNumber#intValue(), JsonObject#getInt()

Should we use one scheme here: getInt() even in JsonNumber ? Then, s/getIntValueExact()/getIntExact()

jfuerth added a comment - 09/Feb/13 05:17 PM

Good point. I thought about that too when I was making the method name changes.

The conclusion I arrived at was that JsonParser#getInt() makes somewhat more sense than JsonParser#intValue(). It matches JsonArray#getInt(int) and JsonObject#getInt(String). Only JsonNumber differs, and for these two reasons:

1. JsonNumber serves a similar purpose to java.lang.Number, and to me this is a strong case for staying with the familiar/expected naming scheme
2. When the JsonObject or JsonArray getter method names match the JsonNumber getter method name, chained calls like jsonObject.getNumber("key").getDouble() don't read as well as jsonObject.getNumber("key").doubleValue().

So my preference is still to stay with getXXX() method names across the whole javax.json API, but go with the very well established java.lang.Number method names on JsonNumber.

jitu added a comment - 10/Feb/13 06:49 AM

Fixing it as suggested.