DATAES-763 - Polishing.

This commit is contained in:
Peter-Josef Meisch 2020-03-22 08:46:57 +01:00
parent a92970236c
commit db28d93676

View File

@ -15,8 +15,17 @@
*/ */
package org.springframework.data.elasticsearch.core.convert; package org.springframework.data.elasticsearch.core.convert;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.elasticsearch.search.aggregations.Aggregations; import org.elasticsearch.search.aggregations.Aggregations;
@ -356,11 +365,8 @@ public class MappingElasticsearchConverter
for (Object value : source) { for (Object value : source) {
if (value == null) { if (value == null) {
return null; target.add(null);
} } else if (isSimpleType(value)) {
if (isSimpleType(value)) {
target.add( target.add(
readSimpleValue(value, targetType.getComponentType() != null ? targetType.getComponentType() : targetType)); readSimpleValue(value, targetType.getComponentType() != null ? targetType.getComponentType() : targetType));
} else { } else {
@ -392,29 +398,31 @@ public class MappingElasticsearchConverter
Map<String, Object> target = new LinkedHashMap<>(); Map<String, Object> target = new LinkedHashMap<>();
for (Entry<String, Object> entry : source.entrySet()) { for (Entry<String, Object> entry : source.entrySet()) {
if(entry.getValue() == null) { String entryKey = entry.getKey();
target.put(entry.getKey(),null); Object entryValue = entry.getValue();
} else if (isSimpleType(entry.getValue())) {
target.put(entry.getKey(), if (entryValue == null) {
readSimpleValue(entry.getValue(), targetType.isMap() ? targetType.getComponentType() : targetType)); target.put(entryKey, null);
} else if (isSimpleType(entryValue)) {
target.put(entryKey,
readSimpleValue(entryValue, targetType.isMap() ? targetType.getComponentType() : targetType));
} else { } else {
ElasticsearchPersistentEntity<?> targetEntity = computeGenericValueTypeForRead(property, entry.getValue()); ElasticsearchPersistentEntity<?> targetEntity = computeGenericValueTypeForRead(property, entryValue);
if (targetEntity.getTypeInformation().isMap()) { if (targetEntity.getTypeInformation().isMap()) {
Map<String, Object> valueMap = (Map<String, Object>) entry.getValue(); Map<String, Object> valueMap = (Map<String, Object>) entryValue;
if (typeMapper.containsTypeInformation(valueMap)) { if (typeMapper.containsTypeInformation(valueMap)) {
target.put(entry.getKey(), readEntity(targetEntity, valueMap)); target.put(entryKey, readEntity(targetEntity, valueMap));
} else { } else {
target.put(entry.getKey(), readValue(valueMap, property, targetEntity.getTypeInformation())); target.put(entryKey, readValue(valueMap, property, targetEntity.getTypeInformation()));
} }
} else if (targetEntity.getTypeInformation().isCollectionLike()) { } else if (targetEntity.getTypeInformation().isCollectionLike()) {
target.put(entry.getKey(), target.put(entryKey, readValue(entryValue, property, targetEntity.getTypeInformation().getActualType()));
readValue(entry.getValue(), property, targetEntity.getTypeInformation().getActualType()));
} else { } else {
target.put(entry.getKey(), readEntity(targetEntity, (Map<String, Object>) entry.getValue())); target.put(entryKey, readEntity(targetEntity, (Map<String, Object>) entryValue));
} }
} }
} }
@ -615,7 +623,14 @@ public class MappingElasticsearchConverter
if (!typeHint.getActualType().getType().equals(Object.class) if (!typeHint.getActualType().getType().equals(Object.class)
&& isSimpleType(typeHint.getMapValueType().getType())) { && isSimpleType(typeHint.getMapValueType().getType())) {
mapSource.forEach(it -> target.put(it.getKey(), getWriteSimpleValue(it.getValue()))); mapSource.forEach(it -> {
if (it.getValue() == null) {
target.put(it.getKey(), null);
} else {
target.put(it.getKey(), getWriteSimpleValue(it.getValue()));
}
});
} else { } else {
mapSource.forEach(it -> { mapSource.forEach(it -> {