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

Empty maps are deserialized as null #860

Closed
gugumonster opened this issue Oct 22, 2015 · 1 comment · Fixed by #869
Closed

Empty maps are deserialized as null #860

gugumonster opened this issue Oct 22, 2015 · 1 comment · Fixed by #869
Labels
Milestone

Comments

@gugumonster
Copy link

When configuring the mapper to also store empties

mapper.getOptions().setStoreEmpties(true);

then empty Maps and Lists are stored as well to DB.
They also get deserialized as empty Maps resp. List again.
This works for an empty

Map<String, String>

BUT it does not work for empty Maps like the following

Map<String, List<String>>
Map<String, MyObject>

where

class MyObject {
   private String valueA;
   private int valueB;
}

It seems when having a complex type in the value part of the map, the map is no longer deserialized as empty map but simply as null object, which subsequently breaks the code as they are no longer equal after loading.

Tested with Morphia 1.0.1

@shils
Copy link
Contributor

shils commented Nov 11, 2015

The issue seems to be that EmbeddedMapper#readMap doesn't take its MapperOptions' isStoreEmpties flag into account when deciding whether to set the map field's value. This doesn't occur for simple valued maps because a different Mapper implementation is used.

I've created a pull request with the necessary changes here #869.

@evanchooly evanchooly added the bug label Dec 18, 2015
@evanchooly evanchooly added this to the 1.1.0 milestone Dec 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants