1

I have the following JSON structure:

{
   "status": "Completed",
   "notes": null,
   "members":    {
      "0":       {
         "year": "2",
         "details":          {
            "id": "14899975",
            "anotherId": "11013306"
         },
         "aName": "Fred",
         "amounts":          {
            "First": 589.48,
            "Second": 1000,
            "Third": 339.48
         }
      },
      "1":       {
         "year": "2",
         "details":          {
            "id": "14899976",
            "anotherId": "11013306"
         },
         "aName": "George",
         "amounts":          {
            "First": 222.22,
            "Second": 2000,
            "Third": 22.22
         }
      },
      "2":       {
         "year": 1,
         "details":          {
            "id": "14899976",
            "anotherId": "11013306"
         },
         "aName": "Albert",
         "amounts":          {
            "First": 333.33,
            "Second": 3000,
            "Third": 33.33
         },
      }
   }
}

I am using Spring RESTTemplate and JacksonMapping2HttpMessageConverter, and the following structures to receive the result of parsing the above JSON structure:

@JsonIgnoreProperties(ignoreUnknown = true)
public class Response {
  private String            status;
  private String            notes;
  private Map<String,Struct1>   quotes;
}

@JsonIgnoreProperties(ignoreUnknown = true)
 class Struct1 {
    private int         year;
    private Struct2     details;
    private String          aName;
    private Struct3     amounts;
}

@JsonIgnoreProperties(ignoreUnknown = true)
 class Struct2 {
    private String id;
    private String anotherId;
}

@JsonIgnoreProperties(ignoreUnknown = true)
 class Struct3 {
    private float First;
    private float Second;
    private float Third;
 }

All of these also have appropriate setters and getters for all fields.

My problem is that the number values in Struct3 are not filled in. I've tried making them float, Float, String, and BigDecimal, and the result is either null or 0.0.

I've tried putting a breakpoint in the setter for the first field, hoping

What am I missing? Can the capital letters in the JSON be causing a problem, do I need alternate field names?

2
  • where is the code for creating your Struct3's? Commented Jan 20, 2017 at 17:42
  • The only code I have for "creating" an instance of all this is calling the RESTTemplate which includes the MappingJackson2HttpMessageConverter; it is filling in all the other fields, except for the ones in Struct3. Commented Jan 20, 2017 at 17:45

1 Answer 1

1

It turned out to be the capital letters at the beginning of the field names; I added annotations like @JsonProperty("First") on the line before the getter of the field, and renamed the field to first, and now it's working.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.