0

I am new to JACKSON serialization, and writing Test cases for model classes. So when i serialise an another object initialized in this model class following anomaly is seen::

Example::

class ToTest{

 ABC abc;

//getter setter

}

class Test{
//everything that is needed
@Test
public void serialize() throws Exception{

ToTest toTest = new ToTest();
ABC abc = new ABC();

toTest.setABC(abc);

}

Now when I serilize this toTest object: the json string is missing the "ABC" class name. So i am not able to equalise them. Please help.

1 Answers1

0

Jackson does not explicitly write out the class names when doing serialization do JSON. This is by design as the POJO objects used in serialization are intended for describing the contents of the JSON data, not necessarily preserving the class.

With that said, there are a few things you can do. If you want to preserve the original class, you can use annotations to add a class field, which might solve your issue. A quick search resulted in this as an example:

include class name in all objects serialized by jackson

Community
  • 1
  • 1
Andrew Phillips
  • 937
  • 1
  • 7
  • 19