zoukankan      html  css  js  c++  java
  • ObjectMapper将json转对象报错处理

    在使用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实体类中,加入无参构造器,即可解决

  • 相关阅读:
    js判断当前年龄
    获取手机号归属地
    关于vscode控制tab控制缩进2/4个空格
    vue中的 mvvm
    关于前端性能优化
    js 深拷贝
    关于js hasOwnPropetry // instanceof 整理
    node-sass 安装报错
    JS发送跨域Post请求出现两次请求的解决办法
    Vue面试复习
  • 原文地址:https://www.cnblogs.com/xuwenjin/p/8976529.html
Copyright © 2011-2022 走看看