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)
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 !!
All of my websites are hosted on Bluehost. Why? Because they make it incredibly easy to get a new site up and running with their one-click automatic WordPress Blog installation.
You can use your Bluehost account to host multiple domains—no need to pay more for hosting when you’re ready to start another website.