码迷,mamicode.com
首页 > 移动开发 > 详细

ObjectMapper将json转对象报错处理

时间:2018-05-01 20:26:14      阅读:1113      评论:0      收藏:0      [点我收藏+]

标签:table   source   mat   lis   bind   sage   AC   exception   serialize   

在使用ObjectMapper将json转对象,调用mapper.readValue(jsonStr, XwjUser.class)时,报如下错:

com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of entity.XwjUser: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
 at [Source: {"id":1,"message":"Hello World","sendTime":1525162183195,"intList":null}; line: 1, column: 2]
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:261)
    at com.fasterxml.jackson.databind.DeserializationContext.instantiationException(DeserializationContext.java:1456)
    at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1012)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1203)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:314)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:148)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3789)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2833)
    at testJson.TestObjectMapper.testObj(TestObjectMapper.java:47)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

  ....

解决办法:在XwjUser实体类中,加入无参构造器,即可解决

 

ObjectMapper将json转对象报错处理

标签:table   source   mat   lis   bind   sage   AC   exception   serialize   

原文地址:https://www.cnblogs.com/xuwenjin/p/8976529.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!