Google 数据存储对象化保存地图问题
Google datastore objectify save issue with map
在 map
中只有一个元素的列表上的 remove(0)
使 map
属性 在保存到 google 数据存储时从实体中消失使用对象化。
"map
" 是数据存储实体中的 属性。
Map<String, List<String>> map;
在以下代码后保存会导致映射 属性 从数据存储中消失,当对应于键 "dress"
的列表只有一个元素时,即使对应于其他键的列表有任意数量元素数。
map.get("dress").remove(0)
注意:当列表中有多个元素时,不会发生此问题。
Java SDK 的默认行为如下(来自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.
您可以更改它以便使用
保留空列表
System.setProperty(DatastoreServiceConfig.DATASTORE_EMPTY_LIST_SUPPORT, Boolean.TRUE.toString())
在打开该功能之前,请务必阅读上面列出的文档部分;它列出了几个需要注意的注意事项。
事实证明,在 Objectify 版本 5.1.8 一直到 5.1.12 中保存地图的方式存在错误。我们升级到 5.1.13,现在可以使用了。
map
中只有一个元素的列表上的 remove(0)
使 map
属性 在保存到 google 数据存储时从实体中消失使用对象化。
"map
" 是数据存储实体中的 属性。
Map<String, List<String>> map;
在以下代码后保存会导致映射 属性 从数据存储中消失,当对应于键 "dress"
的列表只有一个元素时,即使对应于其他键的列表有任意数量元素数。
map.get("dress").remove(0)
注意:当列表中有多个元素时,不会发生此问题。
Java SDK 的默认行为如下(来自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.
您可以更改它以便使用
保留空列表System.setProperty(DatastoreServiceConfig.DATASTORE_EMPTY_LIST_SUPPORT, Boolean.TRUE.toString())
在打开该功能之前,请务必阅读上面列出的文档部分;它列出了几个需要注意的注意事项。
事实证明,在 Objectify 版本 5.1.8 一直到 5.1.12 中保存地图的方式存在错误。我们升级到 5.1.13,现在可以使用了。