Home  >  Forum  >  Core Java
Post New Query

JsonMappingException: No suitable constructor found for type


joined on
June 15,2014
Asked on February 27,2015
Hi, 
I am using Jackson API to parse JSON string. While reading data, getting error for the class.


Exception in thread "main" org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class com.test.Person]: can not instantiate from JSON object (need to add/enable type information?)
 at [Source: java.io.StringReader@129a8472; line: 1, column: 2]
at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObjectUsingNonDefault(BeanDeserializer.java:746)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:683)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2732)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1863)
at com.concretepage.ReadJSONWithObjectMapper.main(ReadJSONWithObjectMapper.java:15)

joined on
October 10,2013
Replied on February 27,2015

While reading JSON, the type of class must have default constructor.  Jackson uses default constructor to initialize the class.  So create a default constructor in your person class as

public Person() {}
joined on
June 15,2014
Replied on February 27,2015

Solution working. Thanks.

Write Answer



Sitewide-Feb4of4234x60





Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us