I have a problem with array deserialization when using JsonIdentityInfo. The serialization takes place correctly and the array contains a few Ids where there are cyclic references. However, I cannot figure out how to deserialize the ids into objects. I get an array with some objects and some strings. [I use UUIDs for ids
@JsonIdentityInfo(
generator=ObjectIdGenerators.UUIDGenerator.class,
property="_lineItemExternalId",
scope=LineItemExternal.class
)
The array is serialized as
{
"@class":".WebServiceResponseArrayImpl",
"responseCode":0,
"responseMessage":"OK",
"systemTime":1486803868384,
"data":[
"[Ljava.io.Serializable;",
[
[
"in.cloudnine.nanoerp.model.inventory.LineItemExternal",
{
"lineItemExternalId":"0379de02-d67d-42b1-a764-d2c53f90e474",
"bags":40,
"serialNumber":"1",
"kgs":2000.00,
"manufacturerBatchNumber":"55",
"rate":250.00,
"subtotal":500000.00,
"virgin":true,
"color":{
"_colorId":"4a811a32-2057-4759-b07f-3d70f1a8ec4a",
"company":"abb1f7e2-c42f-43e6-8b44-341fe744d4c2",
"date":"2017-01-22",
"createdOn":"2017-02-09",
"modifiedOn":"2017-02-09",
"systemUser":"f46e9a61-670d-491c-8571-ba7b2e1a55e7",
"colorId":"85f91038-1e6a-4c73-a2f6-4c0e16e48f7f",
"code":"MG",
"name":"Magenta",
"value":null
},
"manufacturer":{
"_manufacturerId":"80a63b5e-33db-4b13-84cc-b9f591ea6b78"
}
}
],
"cee9d79b-77a9-4b3b-a376-ead1d6347d03",
"a15661e1-b4d4-4145-8db8-4e66ad0e4f81"
]
]
}
Here, "cee9d79b-77a9-4b3b-a376-ead1d6347d03", and "a15661e1-b4d4-4145-8db8-4e66ad0e4f81" are LineItemExternal ids, which have been serialized completely in the above json. [Removed for brevity]
The code which throws the error is
Object[]array=createBeanArrayLineItemExternal();
System.out.println("Length of Array:"+array.length);
for(Object obj:array){
LineItemExternal item=(LineItemExternal)obj;
System.out.println(item);
}
}
catch(ClassCastException e){
e.printStackTrace();
}
It throws ClassCastException saying String cannot be cast to LineItemExternal. This means the array contains one object and two strings [the Ids]
Do I need a custom deserializer or is it possible to configure object mapper to do that automatically?
I previously asked the question on disqus and the link to the project src is below.
https://github.com/ks1974in/DeserializationTestForJson.git
The sample input json is in file input.json in the project folder. The test case is in package in.cloudnine.inventory.test; It is TestSerializationAndDeserialization The failing test is testWithFile()
Sorry for including so much code. But the previous tests with limited code ALL SUCCEEDED. However, the above test does fail with a class cast exception
Thanks, Sagar
Please help me.