DATADOC-228 - MappingMongoConverter now writes null for map values.
Fixes a NPE that one got when trying to persist a Map containing null as value for entries.
This commit is contained in:
@@ -568,7 +568,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
// Don't use conversion service here as removal of ObjectToString converter results in some primitive types not
|
||||
// being convertable
|
||||
String simpleKey = key.toString();
|
||||
if (conversions.isSimpleType(val.getClass())) {
|
||||
if (val == null || conversions.isSimpleType(val.getClass())) {
|
||||
writeSimpleInternal(simpleKey, val, dbo);
|
||||
} else {
|
||||
DBObject newDbo = new BasicDBObject();
|
||||
|
||||
@@ -491,6 +491,23 @@ public class MappingMongoConverterUnitTests {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATADOC-228
|
||||
*/
|
||||
@Test
|
||||
public void writesNullValuesForMaps() {
|
||||
|
||||
ClassWithMapProperty foo = new ClassWithMapProperty();
|
||||
foo.map = Collections.singletonMap(Locale.US, null);
|
||||
|
||||
DBObject result = new BasicDBObject();
|
||||
converter.write(foo, result);
|
||||
|
||||
Object map = result.get("map");
|
||||
assertThat(map, is(instanceOf(DBObject.class)));
|
||||
assertThat(((DBObject) map).keySet(), hasItem("en_US"));
|
||||
}
|
||||
|
||||
class GenericType<T> {
|
||||
T content;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user