Reputation: 41
remove(0)
on a list having just one element in a map
is making the map
property disappear from an entity while saving to google datastore using objectify.
"map
" is a property in the datastore entity.
Map<String, List<String>> map;
Saving after the following code causes the map property to disappear from datastore when the list corresponding to the key "dress"
has just one element even if corresponding to other keys there are lists with any number of elements.
map.get("dress").remove(0)
Note: the issue does not happen when there is more than one element in the list.
Upvotes: 1
Views: 357
Reputation: 41
Turns out there was a bug in the way map was being saved in Objectify version 5.1.8 all the way upto 5.1.12. We upgraded to 5.1.13 and this works now.
Upvotes: 1
Reputation: 6039
The default behavior of the Java SDK is as follows (from the docs):
- Null properties are written as null to the data store
- Empty collections are written as null to data store
- A null is read as null from the data store
- An empty collection is read as null.
You can change that so empty lists are preserved using
System.setProperty(DatastoreServiceConfig.DATASTORE_EMPTY_LIST_SUPPORT, Boolean.TRUE.toString())
Be sure to read the doc section listed above before turning that feature on; it lists several caveats to be aware of.
Upvotes: 0