[Solved]: com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class sample.jackson.Info]: can not instantiate from JSON object



Solution:

Please do not forget to add a default constructor in POJO class, otherwise you will get this error:

Instead of this:

    public class Hollo {        public int id;        public String name; } 

Use this:

    public class Hollo {        public int id;        public String name;     Hollo(){}         } 

because if you will define parameterized constructor then compiler will not generate default constructor. and

        Hoge hello = mapper.readValue(json, Hello.class);

here Hello.class calls for default constructor.

com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class sample.jackson.Info]: can not instantiate from JSON object (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: {\”id\”:20, \”name\”:\”TOM\”}; line: 1, column: 2]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1106)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:296)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:133)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3736)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2726)
at sample.jackson.Main(Main.java:18)