Fix MappingElasticsearchConverter conversion from Document into Map<String, Object>.

Original PR: #436
This commit is contained in:
kkonrad 2020-04-21 20:39:03 +02:00 committed by GitHub
parent 16d8cc22d1
commit 5019793f17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -70,6 +70,7 @@ import org.springframework.util.ObjectUtils;
* @author Peter-Josef Meisch
* @author Mark Paluch
* @author Roman Puchkovskiy
* @author Konrad Kurdej
* @since 3.2
*/
public class MappingElasticsearchConverter
@ -319,7 +320,7 @@ public class MappingElasticsearchConverter
target.put(entryKey, null);
} else if (isSimpleType(entryValue)) {
target.put(entryKey,
readSimpleValue(entryValue, targetType.isMap() ? targetType.getComponentType() : targetType));
readSimpleValue(entryValue, targetType.isMap() ? targetType.getMapValueType() : targetType));
} else {
ElasticsearchPersistentEntity<?> targetEntity = computeGenericValueTypeForRead(property, entryValue);

View File

@ -68,6 +68,7 @@ import org.springframework.lang.Nullable;
* @author Christoph Strobl
* @author Mark Paluch
* @author Peter-Josef Meisch
* @author Konrad Kurdej
*/
public class MappingElasticsearchConverterUnitTests {
@ -662,6 +663,20 @@ public class MappingElasticsearchConverterUnitTests {
assertThat(notification.params.get("content")).isNull();
}
@Test // DATAES-795
void readGenericMapWithSimpleTypes() {
Map<String, Object> mapWithSimpleValues = new HashMap<>();
mapWithSimpleValues.put("int", 1);
mapWithSimpleValues.put("string", "string");
mapWithSimpleValues.put("boolean", true);
Document document = Document.create();
document.put("schemaLessObject", mapWithSimpleValues);
SchemaLessObjectWrapper wrapper = mappingElasticsearchConverter.read(SchemaLessObjectWrapper.class, document);
assertThat(wrapper.getSchemaLessObject()).isEqualTo(mapWithSimpleValues);
}
private String pointTemplate(String name, Point point) {
return String.format(Locale.ENGLISH, "\"%s\":{\"lat\":%.1f,\"lon\":%.1f}", name, point.getX(), point.getY());
}
@ -860,4 +875,12 @@ public class MappingElasticsearchConverterUnitTests {
@GeoPointField private double[] pointD;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
static class SchemaLessObjectWrapper {
private Map<String, Object> schemaLessObject;
}
}