Skip to content

Commit 4876a0e

Browse files
authored
DATAES-797 - Fix MappingElasticsearchConverter recursive descent when reading Map objects.
Original PR: spring-projects#437
1 parent 60cbb67 commit 4876a0e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ private <R> R readCollectionValue(@Nullable List<?> source, ElasticsearchPersist
288288

289289
if (value instanceof List) {
290290
target.add(readValue(value, property, property.getTypeInformation().getActualType()));
291+
} else if (value instanceof Map) {
292+
target.add(readMapValue((Map<String, Object>) value, property, property.getTypeInformation().getActualType()));
291293
} else {
292294
target.add(readEntity(computeGenericValueTypeForRead(property, value), (Map<String, Object>) value));
293295
}

src/test/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverterUnitTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,24 @@ void readGenericMapWithSimpleTypes() {
677677
assertThat(wrapper.getSchemaLessObject()).isEqualTo(mapWithSimpleValues);
678678
}
679679

680+
@Test // DATAES-797
681+
void readGenericListWithMaps() {
682+
Map<String, Object> simpleMap = new HashMap<>();
683+
simpleMap.put("int", 1);
684+
685+
List<Map<String, Object>> listWithSimpleMap = new ArrayList<>();
686+
listWithSimpleMap.add(simpleMap);
687+
688+
Map<String, List<Map<String, Object>>> mapWithSimpleList = new HashMap<>();
689+
mapWithSimpleList.put("someKey", listWithSimpleMap);
690+
691+
Document document = Document.create();
692+
document.put("schemaLessObject", mapWithSimpleList);
693+
694+
SchemaLessObjectWrapper wrapper = mappingElasticsearchConverter.read(SchemaLessObjectWrapper.class, document);
695+
assertThat(wrapper.getSchemaLessObject()).isEqualTo(mapWithSimpleList);
696+
}
697+
680698
private String pointTemplate(String name, Point point) {
681699
return String.format(Locale.ENGLISH, "\"%s\":{\"lat\":%.1f,\"lon\":%.1f}", name, point.getX(), point.getY());
682700
}

0 commit comments

Comments
 (0)