Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GoogleCodeExporter opened this issue Mar 19, 2015 · 3 comments
Labels

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants