json-processing-spec
  1. json-processing-spec
  2. JSON_PROCESSING_SPEC-54

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

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0-pfd
    • Labels:
      None

      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

        Activity

        jfuerth created issue -
        jitu made changes -
        Field Original Value New Value
        Fix Version/s 1.0-pfd [ 16271 ]
        Hide
        jitu added a comment -
        • Your changes have this : JsonParser#getInt(), JsonNumber#intValue(), JsonObject#getInt()

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

        Show
        jitu added a comment - Your changes have this : JsonParser#getInt(), JsonNumber#intValue(), JsonObject#getInt() Should we use one scheme here: getInt() even in JsonNumber ? Then, s/getIntValueExact()/getIntExact()
        Hide
        jfuerth added a comment -

        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.

        Show
        jfuerth added a comment - 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.
        Hide
        jitu added a comment -

        Fixing it as suggested.

        Show
        jitu added a comment - Fixing it as suggested.
        jitu made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            jfuerth
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: