[JSON_PROCESSING_SPEC-54] Shorten getter method names; make chained getters read well when used together Created: 06/Feb/13  Updated: 10/Feb/13  Resolved: 10/Feb/13

Status: Resolved
Project: json-processing-spec
Component/s: None
Affects Version/s: None
Fix Version/s: 1.0-pfd

Type: Improvement Priority: Major
Reporter: jfuerth Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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:

https://github.com/jfuerth/javax-json/commit/shorter-method-names



 Comments   
Comment by jitu [ 08/Feb/13 ]
  • Your changes have this : JsonParser#getInt(), JsonNumber#intValue(), JsonObject#getInt()

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

Comment by jfuerth [ 09/Feb/13 ]

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.

Comment by jitu [ 10/Feb/13 ]

Fixing it as suggested.

Generated at Thu Dec 08 18:52:23 UTC 2016 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.