Skip to content

Commit 5019793

Browse files
authored
Fix MappingElasticsearchConverter conversion from Document into Map<String, Object>.
Original PR: spring-projects#436
1 parent 16d8cc2 commit 5019793

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
* @author Peter-Josef Meisch
7171
* @author Mark Paluch
7272
* @author Roman Puchkovskiy
73+
* @author Konrad Kurdej
7374
* @since 3.2
7475
*/
7576
public class MappingElasticsearchConverter
@@ -319,7 +320,7 @@ private <R> R readMapValue(@Nullable Map<String, Object> source, ElasticsearchPe
319320
target.put(entryKey, null);
320321
} else if (isSimpleType(entryValue)) {
321322
target.put(entryKey,
322-
readSimpleValue(entryValue, targetType.isMap() ? targetType.getComponentType() : targetType));
323+
readSimpleValue(entryValue, targetType.isMap() ? targetType.getMapValueType() : targetType));
323324
} else {
324325

325326
ElasticsearchPersistentEntity<?> targetEntity = computeGenericValueTypeForRead(property, entryValue);

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
* @author Christoph Strobl
6969
* @author Mark Paluch
7070
* @author Peter-Josef Meisch
71+
* @author Konrad Kurdej
7172
*/
7273
public class MappingElasticsearchConverterUnitTests {
7374

@@ -662,6 +663,20 @@ void readEntityWithMapDataType() {
662663
assertThat(notification.params.get("content")).isNull();
663664
}
664665

666+
@Test // DATAES-795
667+
void readGenericMapWithSimpleTypes() {
668+
Map<String, Object> mapWithSimpleValues = new HashMap<>();
669+
mapWithSimpleValues.put("int", 1);
670+
mapWithSimpleValues.put("string", "string");
671+
mapWithSimpleValues.put("boolean", true);
672+
673+
Document document = Document.create();
674+
document.put("schemaLessObject", mapWithSimpleValues);
675+
676+
SchemaLessObjectWrapper wrapper = mappingElasticsearchConverter.read(SchemaLessObjectWrapper.class, document);
677+
assertThat(wrapper.getSchemaLessObject()).isEqualTo(mapWithSimpleValues);
678+
}
679+
665680
private String pointTemplate(String name, Point point) {
666681
return String.format(Locale.ENGLISH, "\"%s\":{\"lat\":%.1f,\"lon\":%.1f}", name, point.getX(), point.getY());
667682
}
@@ -860,4 +875,12 @@ static class GeoEntity {
860875

861876
@GeoPointField private double[] pointD;
862877
}
878+
879+
@Data
880+
@NoArgsConstructor
881+
@AllArgsConstructor
882+
static class SchemaLessObjectWrapper {
883+
884+
private Map<String, Object> schemaLessObject;
885+
}
863886
}

0 commit comments

Comments
 (0)