我有一个JSONString如下:
{"items":[{"attribute":"grade","values":["AA"]},{"attribute":"subject","values":["mathematics"]}]}
我创建了一个Marks类,如下所示:
@Builder
@Getter
@Setter
@ToString
public class Marks {
@JsonProperty("attribute")
private String attributeName;
List<String> values;
}
当我执行以下行时:
List<Marks> markList = objectMapper.readValue(actionPriorityConfig, new TypeReference<Marks>());
我遇到以下异常:
com.fasterxml.jackson.databind.JsonMappingException: Can not
deserialize instance of
com.amazon.avstech.autoallocation.model.AttributeAutoAllocNotEligibility out of START_ARRAY token
at [Source: [{"values":["AA"],"attribute":"grade"},{"values":["mathematics"],"attribute":"subject"}]; line: 1, column: 1]
答案 0 :(得分:0)
似乎您尝试在Mark
个对象中转换它,但items
包含Mark
数组。
答案 1 :(得分:0)
您可以尝试在属性值声明之前添加@JsonProperty(&#34; values&#34;)。
ng update
答案 2 :(得分:0)
您的Json字符串有效,但它不是Json数组。
您可以将Json数组更改为以下格式并再次检查。
[{"attribute":"grade","values":["AA"]},{"attribute":"subject","values":["mathematics"]}]
尝试以下,
String actionPriorityConfig= "[{\"attribute\":\"grade\",\"values\":[\"AA\"]},{\"attribute\":\"subject\",\"values\":[\"mathematics\"]}]";
ObjectMapper objectMapper = new ObjectMapper();
List<Marks> markList = objectMapper.readValue(actionPriorityConfig, new TypeReference<Marks>());