mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-09-04 08:20:03 +00:00
fix[orm]: map null value support
This commit is contained in:
@@ -50,7 +50,12 @@ public class IntMapCodec<V> implements Codec<Map<Integer, V>> {
|
||||
var map = new HashMap<Integer, V>();
|
||||
while (!BsonType.END_OF_DOCUMENT.equals(reader.readBsonType())) {
|
||||
int key = Integer.parseInt(reader.readName());
|
||||
V value = BsonType.NULL.equals(reader.getCurrentBsonType()) ? null : valueCodec.decode(reader, context);
|
||||
V value = null;
|
||||
if (BsonType.NULL.equals(reader.getCurrentBsonType())) {
|
||||
reader.readNull();
|
||||
} else {
|
||||
value = valueCodec.decode(reader, context);
|
||||
}
|
||||
map.put(key, value);
|
||||
}
|
||||
reader.readEndDocument();
|
||||
|
||||
@@ -45,8 +45,8 @@ public class MapTest {
|
||||
|
||||
var itemMap = new HashMap<String, Item>();
|
||||
itemMap.put("1", new Item(1, "item1"));
|
||||
itemMap.put("2", new Item(2, "item1"));
|
||||
itemMap.put("3", new Item(3, "item1"));
|
||||
itemMap.put("2", new Item(2, "item2"));
|
||||
itemMap.put("3", new Item(3, "item3"));
|
||||
|
||||
var bagItem1 = new BagItem(1, "desc1", itemMap);
|
||||
var bagItem2 = new BagItem(2, "desc2", itemMap);
|
||||
@@ -64,13 +64,15 @@ public class MapTest {
|
||||
var longStringHashMap = new HashMap<Long, String>();
|
||||
longStringHashMap.put(100L, "hello map1");
|
||||
longStringHashMap.put(101L, "hello map2");
|
||||
longStringHashMap.put(102L, null);
|
||||
longStringHashMap.put(103L, "hello map3");
|
||||
longStringHashMap.put(104L, null);
|
||||
entity.setLongStringMap(longStringHashMap);
|
||||
|
||||
var intStringHashMap = new HashMap<Integer, String>();
|
||||
intStringHashMap.put(100, "hello map1");
|
||||
intStringHashMap.put(102, "hello map2");
|
||||
intStringHashMap.put(103, "hello map2");
|
||||
intStringHashMap.put(103, "hello map3");
|
||||
intStringHashMap.put(104, null);
|
||||
entity.setIntStringMap(intStringHashMap);
|
||||
|
||||
var intBagMap = new HashMap<Integer, BagItem>();
|
||||
@@ -83,6 +85,7 @@ public class MapTest {
|
||||
intBaseMap.put(1, Map.of(1, "1"));
|
||||
intBaseMap.put(2, Map.of(2, "2"));
|
||||
intBaseMap.put(3, Map.of(3, "3"));
|
||||
intBaseMap.put(4, null);
|
||||
entity.setIntBaseMap(intBaseMap);
|
||||
|
||||
OrmContext.getAccessor().insert(entity);
|
||||
|
||||
Reference in New Issue
Block a user