解决com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simpl
在使用jackson 进行json字符串转java bean的时候出现如下错误,
com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class org.test.Library]: can not instantiate from JSON object (need to add/enable type information?) at [Source: java.io.StringReader@d1831; line: 1, column: 2]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:983)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:276)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2034)
原因java bean中没有提供无参的构造函数,如下
public class Library { private String name; private List<Book> bookList ; //添加无参的构造器 public Library(){ } public Library(String name){ this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } public List<Book> getBookList() { return bookList; } public void setBookList(List<Book> bookList) { this.bookList = bookList; } }
来源://作者:/更新时间:2014-05-16
顶
踩
相关文章:
- junit java.lang.NoClassDefFoundError: net/minidev/
- junit java.lang.NoClassDefFoundError: com/jayway/j
- junit java.lang.AssertionError: Status expected:<2
- junit测试 jsonPath如何获取json数据里面对象的个数大
- 使用jackson json处理java对象和json数据相互转换
- srpingmvc 返回json数据日期格式化方法
- java 参数传list多个对象数据的方法
- 解决Error querying database. Cause: java.lang.Ill
- java.util.concurrent.ExecutionException: Failed to
- java 通过batik 把svg格式的矢量图生成png图片