DATAES-892 - Fix ElasticsearchEntityMapper recursive descent when reading Map objects.

This commit is contained in:
Peter-Josef Meisch 2020-07-29 21:17:21 +02:00
parent ee660bb208
commit bf5eaae357
2 changed files with 29 additions and 0 deletions

View File

@ -294,6 +294,9 @@ public class ElasticsearchEntityMapper implements
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) value));
}

View File

@ -531,6 +531,32 @@ public class ElasticsearchEntityMapperUnitTests {
assertThat(target.address).isEqualTo(bigBunsCafe);
}
@Test // DATAES-892
public 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);
Map<String, Object> document = new LinkedHashMap<>();
document.put("schemaLessObject", mapWithSimpleList);
SchemaLessObjectWrapper wrapper = entityMapper.read(SchemaLessObjectWrapper.class, document);
assertThat(wrapper.getSchemaLessObject()).isEqualTo(mapWithSimpleList);
}
@Data
@NoArgsConstructor
@AllArgsConstructor
static class SchemaLessObjectWrapper {
private Map<String, Object> schemaLessObject;
}
private String pointTemplate(String name, Point point) {
return String.format(Locale.ENGLISH, "\"%s\":{\"lat\":%.1f,\"lon\":%.1f}", name, point.getX(), point.getY());
}