mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-21 11:32:12 +00:00
DATAES-892 - Fix ElasticsearchEntityMapper recursive descent when reading Map objects.
This commit is contained in:
parent
ee660bb208
commit
bf5eaae357
@ -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));
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user