Home  >  Forum  >  Core Java
Post New Query

No ObjectCodec defined for the generator, can only serialize simple wrapper type

joined on
June 15,2014
Asked on February 28,2015
I am new to Jackson API. While using Jackson JsonGenerator, I am getting below error. I am using code as below. 

JsonGenerator jsonGen = jsonFactory.createJsonGenerator(fos, JsonEncoding.UTF8);
Person person = new Person(10, "ABCD", address);

But getting error.

Exception in thread "main" java.lang.IllegalStateException: No ObjectCodec defined for the generator, can only serialize simple wrapper types (type passed com.concretepage.Person)
at org.codehaus.jackson.impl.JsonGeneratorBase._writeSimpleObject(JsonGeneratorBase.java:556)
at org.codehaus.jackson.impl.JsonGeneratorBase.writeObject(JsonGeneratorBase.java:317)
joined on
October 10,2013
Replied on February 28,2015

You need to set ObjectCodec in JsonGenerator.  ObjectMapper is an ObjectCodec because it  is extended by ObjectMapper. Add the line of code as 

jsonGen.setCodec(new ObjectMapper());
joined on
February 22,2015
Replied on March 01,2015

Class ObjectCodec java.lang.Object extended by org.codehaus.jackson.ObjectCodec Direct Known Subclasses: ObjectMapper public abstract class ObjectCodec extends Object Abstract class that defines the interface that JsonParser and JsonGenerator use to serialize and deserialize regular Java objects (POJOs aka Beans). The standard implementation of this class is ObjectMapper.

Write Answer

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