Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8205603

Deserialization of json into java object fails on Linux but works fine on Mac OS

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      linux

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Red Hat Enterprise Linux Server release 6.7 (Santiago)

      A DESCRIPTION OF THE PROBLEM :
      Deserialization of json into java object fails on Linux but works fine on Mac OS
      with the below exception:
      ERROR [2018-05-11 18:45:17,722] com.pack.model.PropertyUpdateHandler: com.fasterxml.jackson.databind.JsonMappingException: Could not find creator property with name 'name' (in class com.pack.model.BranchModel)
      at [Source: [{"name":"testBranch","label":"B","isDefault":false}]; line: 1, column: 1]

      REGRESSION : Last worked in version 8u162

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      List<BranchModel> branchModelList = mapper.readValue(value, mapper
                          .getTypeFactory()
                          .constructCollectionType(List.class, BranchModel.class));

      public class BranchModel {
         @JsonInclude(JsonInclude.Include.ALWAYS)
          private final String label;

          @JsonInclude(JsonInclude.Include.NON_NULL)
          private final String name;

          @JsonInclude(JsonInclude.Include.ALWAYS)
          private final boolean isDefault;

             @JsonCreator
          public BranchModel(@JsonProperty("label") String label,
                             @JsonProperty("name") String name,
                             @JsonProperty("isDefault") boolean isDefault) {
                      this.label = label;
                      this.name = name;
                      this.isDefault = isDefault;
          }

         public BranchModel(@JsonProperty("label") String label,
                              @JsonProperty("isDefault") boolean isDefault) {
                     this.label = label;
                      this.name = "empty";
                      this.isDefault = isDefault;
         }

          public String getLabel() {
              return label;
          }

          public String getName() {
              return name;
          }

      public boolean getIsDefault() {
              return isDefault;
          }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      should be able to deserialize.
      ACTUAL -
      exception occurred

      ---------- BEGIN SOURCE ----------
      List<BranchModel> branchModelList = mapper.readValue(value, mapper
                          .getTypeFactory()
                          .constructCollectionType(List.class, BranchModel.class));

      public class BranchModel {
         @JsonInclude(JsonInclude.Include.ALWAYS)
          private final String label;

          @JsonInclude(JsonInclude.Include.NON_NULL)
          private final String name;

          @JsonInclude(JsonInclude.Include.ALWAYS)
          private final boolean isDefault;

             @JsonCreator
          public BranchModel(@JsonProperty("label") String label,
                             @JsonProperty("name") String name,
                             @JsonProperty("isDefault") boolean isDefault) {
                      this.label = label;
                      this.name = name;
                      this.isDefault = isDefault;
          }

         public BranchModel(@JsonProperty("label") String label,
                              @JsonProperty("isDefault") boolean isDefault) {
                     this.label = label;
                      this.name = "empty";
                      this.isDefault = isDefault;
         }

          public String getLabel() {
              return label;
          }

          public String getName() {
              return name;
          }

      public boolean getIsDefault() {
              return isDefault;
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      remove the second constructor.

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              psonal Pallavi Sonal (Inactive)
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: