boonproject / boon

Simple opinionated Java for the novice to expert level Java Programmer. Low Ceremony. High Productivity.
http://richardhightower.github.io/site/Boon/Welcome.html
Apache License 2.0
520 stars 102 forks source link

Problem with Generics types #359

Open piyushGoyal2 opened 7 years ago

piyushGoyal2 commented 7 years ago

I have a classic use case of converting a map to JSON. The only catch here is the Map's value is instance of sub classses of an abstract class. Refer to following code:

public Map<String, JsonAbstractClassB> jsonMap;

where JsonAbstractClassB has two different sub classes JsonClassC and JsonClassD.

While setting the object of class C and class D and serializing works perfectly fine. When I deserialize a json back. All I get is instance of JsonAbstractClassB. Boon does not return me the instance of JsonClassC and JsonClassD.

I was referring to the example https://github.com/boonproject/boon/wiki/Boon-JSON-in-five-minutes#subclasses-interfaces-and-abstract-classes

and could see that if the object of abstract classes and sub classes are not wrapped in a collection, they work perfectly fine during deserialization but not when wrapped in collection.

Any help is highly appreciated.