DATAES-797 - Fix MappingElasticsearchConverter recursive descent when reading Map objects.

Original PR: #437
This commit is contained in:
Peter-Josef Meisch 2020-04-23 08:01:46 +02:00 committed by GitHub
parent 60cbb67877
commit 4876a0e3ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -288,6 +288,8 @@ public class MappingElasticsearchConverter
if (value instanceof List) {
target.add(readValue(value, property, property.getTypeInformation().getActualType()));
} else if (value instanceof Map) {
target.add(readMapValue((Map<String, Object>) value, property, property.getTypeInformation().getActualType()));
} else {
target.add(readEntity(computeGenericValueTypeForRead(property, value), (Map<String, Object>) value));
}

View File

@ -677,6 +677,24 @@ public class MappingElasticsearchConverterUnitTests {
assertThat(wrapper.getSchemaLessObject()).isEqualTo(mapWithSimpleValues);
}
@Test // DATAES-797
void readGenericListWithMaps() {
Map<String, Object> simpleMap = new HashMap<>();
simpleMap.put("int", 1);
List<Map<String, Object>> listWithSimpleMap = new ArrayList<>();
listWithSimpleMap.add(simpleMap);
Map<String, List<Map<String, Object>>> mapWithSimpleList = new HashMap<>();
mapWithSimpleList.put("someKey", listWithSimpleMap);
Document document = Document.create();
document.put("schemaLessObject", mapWithSimpleList);
SchemaLessObjectWrapper wrapper = mappingElasticsearchConverter.read(SchemaLessObjectWrapper.class, document);
assertThat(wrapper.getSchemaLessObject()).isEqualTo(mapWithSimpleList);
}
private String pointTemplate(String name, Point point) {
return String.format(Locale.ENGLISH, "\"%s\":{\"lat\":%.1f,\"lon\":%.1f}", name, point.getX(), point.getY());
}