Fix NPE when traversing map.
We now use regular iteration instead of the Stream API. Closes: #4567 Original pull request: #4568
This commit is contained in:
committed by
Mark Paluch
parent
e20d12fe34
commit
3dccdd2bc2
@@ -617,15 +617,20 @@ public class QueryMapper {
|
|||||||
|
|
||||||
if (source instanceof Map<?,?> sourceMap) {
|
if (source instanceof Map<?,?> sourceMap) {
|
||||||
|
|
||||||
return sourceMap.entrySet().stream().collect(Collectors.toMap(
|
Map<String, Object> map = new LinkedHashMap<>(sourceMap.size(), 1F);
|
||||||
entry -> ObjectUtils.nullSafeToString(converter.convertToMongoType(entry.getKey())),
|
|
||||||
entry -> {
|
sourceMap.entrySet().forEach(it -> {
|
||||||
if (entry.getValue() instanceof Document document) {
|
|
||||||
return getMappedObject(document, entity);
|
String key = ObjectUtils.nullSafeToString(converter.convertToMongoType(it.getKey()));
|
||||||
}
|
|
||||||
return delegateConvertToMongoType(entry.getValue(), entity);
|
if (it.getValue() instanceof Document document) {
|
||||||
}
|
map.put(key, getMappedObject(document, entity));
|
||||||
));
|
} else {
|
||||||
|
map.put(key, delegateConvertToMongoType(it.getValue(), entity));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
return delegateConvertToMongoType(source, entity);
|
return delegateConvertToMongoType(source, entity);
|
||||||
|
|||||||
@@ -762,6 +762,18 @@ class UpdateMapperUnitTests {
|
|||||||
assertThat(mappedUpdate).doesNotContainKey("$set.concreteMap.jasnah._class");
|
assertThat(mappedUpdate).doesNotContainKey("$set.concreteMap.jasnah._class");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // GH-4567
|
||||||
|
void updateShouldAllowNullValuesInMap() {
|
||||||
|
|
||||||
|
Map<Object, NestedDocument> map = Collections.singletonMap("jasnah", new NestedDocument("kholin"));
|
||||||
|
|
||||||
|
Update update = new Update().set("concreteMap", Collections.singletonMap("jasnah", null));
|
||||||
|
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
|
||||||
|
context.getPersistentEntity(EntityWithObjectMap.class));
|
||||||
|
|
||||||
|
assertThat(mappedUpdate).isEqualTo(new Document("$set", new Document("concreteMap", Collections.singletonMap("jasnah", null))));
|
||||||
|
}
|
||||||
|
|
||||||
@Test // DATAMONGO-1250
|
@Test // DATAMONGO-1250
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void mapsUpdateWithBothReadingAndWritingConverterRegistered() {
|
void mapsUpdateWithBothReadingAndWritingConverterRegistered() {
|
||||||
|
|||||||
Reference in New Issue
Block a user