[Solved] org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type

If you are working on Jackson library and trying to marshal/unmarshal java objects to / from JSON documents, you may encounter this exception.

The exception stack-trace for JsonMappingException looks like this:

org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class test.jackson.Employee]: can not instantiate from JSON object (need to add/enable type information?)
 at [Source: c:\temp\employee.json; line: 1, column: 2]
	at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
	at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:483)
	at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:350)
	at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2395)
	at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1549)
	at test.jackson.JSONToJavaExample.main(JSONToJavaExample.java:19)

exceptions-notes

Solution:

To solve this exception, all you have to do is to create the default constructor for your POJO class which you are trying to marshal/unmarshal. This simple solution will fix this error.


You are missing default constructor in your POJO class. Provide one.

Happy Learning !!

Leave a Reply

3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial