RE: JSON deserializer fails in Liferay 7

Selva kumar, modified 6 Years ago. Junior Member Posts: 39 Join Date: 7/23/15 Recent Posts
Hi All

Am migrating the portlets from 6.2 to 7. The JSON deserialization is not working as expected.

Below is the piece of code.

Map<String, List<VO>> itemMap = new HashMap<>();


JSONSerializer serializer = JSONFactoryUtil.createJSONSerializer();
for (Entry<String, List<VO>> entry : itemMap.entrySet()) {            
            MultiVMPoolUtil.getCache("masterkey").put(entry.getKey(), serializer.serialize(entry.getValue()), 60000);
        }

here the serialization doesn't happen with the class hint. In 6.2, the serialized string is 
[{name: "x", age: 10, class: "com.VO"},{name: "y", age: 20, class: "com.VO"}]

but in 7 version it is 
[{name: "x", age: 10},{name: "y", age: 20}]

due to this, while deserializing it back, rather than getting as List<VO> am getting List<HashMap>

In case if am try to store the object rather than serializing, am getting classcast exception. I think thats due to the classloader issue.

Can someone help on this?

Regards
SK
thumbnail
Amos Fong, modified 6 Years ago. Liferay Legend Posts: 2047 Join Date: 10/7/08 Recent Posts
Maybe try using the JSONFactoryUtil.serialize() method instead?

Also, I think you'll need to add your class to this property if you want to deserialize it properly:

json.deserialization.whitelist.class.names=\
Selva kumar, modified 6 Years ago. Junior Member Posts: 39 Join Date: 7/23/15 Recent Posts
It's not a correct solution. 
It is not possible to white list the classes.
Am moving with Jackson.

Thanks for your reply.