Home  >  Forum  >  Core Java
Post New Query

JsonMappingException: No suitable constructor found for type

Asked on February 27, 2015
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)

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() {}

Replied on February 27, 2015
Solution working. Thanks.

Write Answer

©2022 concretepage.com | Privacy Policy | Contact Us