反序列化json字符串时出现异常

时间:2017-05-15 13:05:58

标签: json

While parsing json string as - {"reportingDate":[2017,4,30]}. 

I am getting com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_ARRAY token

以下是该计划 -

JSON DESERIALIZING CODE -

ObjectMapper mapper = new ObjectMapper();
                            String dbString = "{\"reportingDate\":[2017,4,30]}";
            Map<String, Object> map = new HashMap<String, Object>();

            // convert JSON string to Map
            map = mapper.readValue(dbString, new TypeReference<Map<String, String>>(){});

            System.out.println(map);

1 个答案:

答案 0 :(得分:0)

您的JSON类型引用映射错误,reportingDatearray类型,但您将其转换为字符串

更改

map = mapper.readValue(dbString, new TypeReference<Map<String, String>>(){});

map = mapper.readValue(dbString, new TypeReference<Map<String, Object>>(){});