JSON解析器不返回数字

时间:2017-01-20 17:40:12

标签: java json

我有以下JSON结构:

{
   "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
         },
      }
   }
}

我正在使用Spring RESTTemplate和JacksonMapping2HttpMessageConverter,以及以下结构来接收解析上述JSON结构的结果:

@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;
 }

所有这些都有适合所有领域的制定者和吸气剂。

我的问题是没有填写Struct3中的数字值。我尝试将它们设置为float,Float,String和BigDecimal,结果为null或0.0。

我尝试在第一个字段的setter中放置一个断点,希望

我错过了什么? JSON中的大写字母是否会导致问题,我是否需要备用字段名称?

1 个答案:

答案 0 :(得分:1)

原来是字段名称开头的大写字母;我在字段的getter之前的行上添加了@JsonProperty("First")之类的注释,并将字段重命名为first,现在它正在工作。