Uploaded image for project: 'Ranger'
  1. Ranger
  2. RANGER-4225

Possible Jackson serialization issue due to not comply with Java bean standards

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Patch Available
    • Major
    • Resolution: Unresolved
    • 2.4.0
    • 3.0.0
    • Ranger
    • None

    Description

      PROBLEM:

      Transitive Jackson-2 dependencies are included into Ranger's classpath in my env and conflicted with Jackson-1 dependencies.

      Jackson-2 uses Javabean naming conventions to figure out the Json properties in a Java class, and some of the Ranger's model classes don't comply with the convention.

      For example, when the leading camelcase word is only one letter in length, then deserialized response is broken. The following is what I observed in Ranger v2.4.0;

      On Ranger UI side, this code-block attempts to read vXStrings key in map, but the corresponding response has vxstrings instead:

      {
          "startIndex": 0,
          "pageSize": 200,
          "totalCount": 11,
          "resultSize": 11,
          "sortType": "asc",
          "sortBy": "id",
          "listSize": 11,
          "vxstrings": [        <==================== here! This has to be vXStrings
              {
                  "value": "public",
                  ... 

      And this difference causes below error while reading the property, therefore the corresponding dropdown has no values as excepted;

      PermissionList.js?ver=build.version:226 Uncaught TypeError: Cannot read properties of undefined (reading 'map')
          at Object.results (PermissionList.js?ver=build.version:226:34)
          at Object.success (select2.js?ver=build.version:450:47)
          at u (jquery-3.3.1.min.js?ver=build.version:2:27457)
          at Object.fireWith [as resolveWith] (jquery-3.3.1.min.js?ver=build.version:2:28202)
          at k (jquery-3.3.1.min.js?ver=build.version:2:77651)
          at XMLHttpRequest.<anonymous> (jquery-3.3.1.min.js?ver=build.version:2:79907)

      REFERENCES:

      Please see this reference related to capital letters http://futuretask.blogspot.com/2005/01/java-tip-6-dont-capitalize-first-two.html

      "Don't capitalize first two letters of a bean property name. This is in our java standards. You should not create a java bean property name that begins with a capital letter in the 1st two places."

      Also you can see the same issue is reported here https://stackoverflow.com/questions/30205006/why-does-jackson-2-not-recognize-the-first-capital-letter-if-the-leading-camel-c 

      SOLUTION:

      @JsonProperty annotation needs to be added for mapping the properties with their corresponding getter/setter methods. This will not effect Ranger's functionality directly, but it will provide consistency even if Jackson-2 is included into classpath.

      I have tested it locally after adding @JsonProperty and everything worked well.

      The PR is attached.

      Attachments

        1. RANGER-4225.patch
          35 kB
          Sercan Tekin

        Issue Links

          Activity

            People

              sercan.tekin Sercan Tekin
              sercan.tekin Sercan Tekin
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h