com.fasterxml.jackson.databind.JsonMappingException:No suitable constructor found for type
2017-08-11 14:28
861 查看
1.有可能是反序列的类确实没有默认构造方法,检查一下。
2.因为我遇到的问题不属于1的情况(最后发现是内部类的问题),首先我是建立了这样一个类,作用是作一个序列化和反序列化的测试:
然后运行之后发现这个错误
说是反序列化的类没有constructor 或者 creator,然后我把内部类单独放到外面,新建一个类,这个问题就没有了,具体是什么原因我也没有深究。
2.因为我遇到的问题不属于1的情况(最后发现是内部类的问题),首先我是建立了这样一个类,作用是作一个序列化和反序列化的测试:
public class Test { @org.junit.Test public void main() throws Exception { Seiral seiral = new Seiral(); seiral.setId("1"); seiral.setName("hhh"); ObjectMapper mapper = new ObjectMapper(); String ooo = mapper.writeValueAsString(seiral); System.out.println(ooo); Seiral ss = mapper.readValue(ooo, Seiral.class); System.out.println(ss); } public class Seiral implements Serializable { private static final long serialVersionUID = 1L; private String id; private transient String name; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "id:" + id + ", name:" + name; } }
然后运行之后发现这个错误
com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class com.bonc.vbap.data.dataset.Test$Seiral]: can not instantiate from JSON object (missing default constructor or creator, or perhaps need to add/enable type information?) at [Source: {"id":"11111","name":"test"}; line: 1, column: 2] at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148) .....
说是反序列化的类没有constructor 或者 creator,然后我把内部类单独放到外面,新建一个类,这个问题就没有了,具体是什么原因我也没有深究。
相关文章推荐
- com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.apache.ibati
- com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class ...
- 解决com.fasterxml.jackson.databind.JsonMappingException: No suitable 以 Jackson 处理复杂类型(List,map)两种方法
- org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type
- org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [si
- JsonMappingException: No suitable constructor found for type
- com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
- com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize out of START_ARRAY token
- nested exception is com.fasterxml.jackson.databind.JsonMappingException: Conflicting getter definiti
- zeppelin spark interpreter异常 com.fasterxml.jackson.databind.JsonMappingException
- Json转对象失败:"No suitable constructor found for type [simple type, class com.test.faster.domain.respons
- com.fasterxml.jackson.databind.JsonMappingException
- com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize out of START_ARRAY token
- java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectWriter.forType
- java.lang.ClassNotFoundException: com.fasterxml.jackson.core.JsonProcessingException
- java.lang.ClassNotFoundException: com.fasterxml.jackson.core.JsonProcessingException
- 关于springmvc中jackson的No suitable constructor found for type错误
- java.lang.ClassNotFoundException: com.fasterxml.jackson.core.JsonProcessingException
- (转) java.lang.ClassNotFoundException: com.fasterxml.jackson.core.JsonProcessingException
- java.lang.ClassNotFoundException: com.fasterxml.jackson.datatype.joda.JodaModule