1
votes

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.

2
You mean having an empty list in a map with other elements causes the whole list to be discarded? Sounds like a bug to me. - Eric Simonton
Yes. only while removing an element if the list becomes empty, then the whole map is discarded. - Vignesh Gowda
@Eric Actually I just noticed, even if you have just a list property in a entity and when you remove the last element in the list, the whole list is discarded. I would expect there to be an empty list. - Vignesh Gowda
Oh I had a mistake in my comment. Does an empty list cause the entire map to be discarded, or does it only cause that entry to be discarded? The latter would not surprise me, though I cannot find anything in the docs about it. - Eric Simonton
If removing an element from a list makes the list empty, then the map this list is part of is discarded. In addition what I noticed was, if the list was a direct entry in the entity instead of being part of the map, then too the list entry is discarded when you do a remove of the last element in the list. I would expect there to be an empty list in this case. I am guessing the above two are related? - Vignesh Gowda

2 Answers

1
votes

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.

0
votes

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.