Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: JSON deserializer fails in Liferay 7
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
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
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:
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=\
It's not a correct solution.
It is not possible to white list the classes.
Am moving with Jackson.
Thanks for your reply.
It is not possible to white list the classes.
Am moving with Jackson.
Thanks for your reply.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™