abhijeetjais20 / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

Gson can't construct subclasses of HashMap without a default constructor #419

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
If we have a subclass of HashMap without a default constructor, Gson uses 
LinkedHashMap as the object type. This isn't correct since we should have 
instead tried to use UnsafeAllocator.

Original issue reported on code.google.com by inder123 on 11 Mar 2012 at 9:42

GoogleCodeExporter commented 9 years ago
Added a failing test to illustrate this bug:
http://code.google.com/p/google-gson/source/detail?r=1129

Original comment by inder123 on 11 Mar 2012 at 9:39

GoogleCodeExporter commented 9 years ago
Does it work if you register an InstanceCreator? I'm anxious about using 
UnsafeAllocator on map and collection types. Types like HashMap expect their 
constructors to run (and initialize state) but they won't necessarily get run 
if we rely on UnsafeAllocator. (We'd be relying on the presence of a no-args 
constructor).

Original comment by limpbizkit on 18 Mar 2012 at 6:01

GoogleCodeExporter commented 9 years ago
Yes, it works if I register an InstanceCreator. My specific issue is resolved, 
I added a no-args constructor. My concern is about keeping parity for this 
feature. Either we support for all types, or we dont.

Original comment by inder123 on 18 Mar 2012 at 7:02