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

Replace generic get methods in JsonArray & JsonObject with specific getters for object, array & number

    Details

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

      Description

      Example of how this change affects a typical task such as pulling a numeric value out of a nested object:

      Given a JSON data structure:

          {
              "id": 1234,
              "location": {
                  "lat": 39.12333432,
                  "long": -79.12344534
              }
          }
      

      fetch the latitude from the nested "location" object.

      BEFORE:

          JsonObject jo = ...;
          double lat = jo.get("location", JsonObject.class).get("lat", JsonNumber.class).getDoubleValue();
      

      AFTER:

          JsonObject jo = ...;
          double lat = jo.getObject("location").getNumber("lat").doubleValue();
      

      I've implemented this together with shortening of getter names (drop 'Value' from getter method names; adjusted JsonNumber to use the familiar java.lang.Number method naming convention)

      You can play with it by pulling from here:

      https://github.com/jfuerth/javax-json/commit/c88ec370a78154fa348758b9edbf022cf746d301

        Activity

        jfuerth created issue -
        jitu made changes -
        Field Original Value New Value
        Fix Version/s 1.0-pfd [ 16271 ]
        Due Date 2013-02-08 00:00:00.0
        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

            • Due:
              Created:
              Updated:
              Resolved: