Skip to content

Commit 92f1684

Browse files
committed
DATAES-865 - Polishing.
1 parent 1de1aeb commit 92f1684

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,9 @@ private Object writeMapValue(Map<String, Object> value, ElasticsearchPersistentP
596596
Map<Object, Object> target = new LinkedHashMap<>();
597597
Streamable<Entry<String, Object>> mapSource = Streamable.of(value.entrySet());
598598

599-
if (typeHint.getActualType() != null && !typeHint.getActualType().getType().equals(Object.class)
599+
TypeInformation<?> actualType = typeHint.getActualType();
600+
601+
if (actualType != null && !actualType.getType().equals(Object.class)
600602
&& isSimpleType(typeHint.getMapValueType().getType())) {
601603
mapSource.forEach(it -> {
602604

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,30 @@ void shouldReadEntityWithListOfGeoPoints() {
789789
assertThat(entity.locations).containsExactly(new GeoPoint(12.34, 23.45), new GeoPoint(34.56, 45.67));
790790
}
791791

792+
@Test // DATAES-865
793+
void shouldWriteEntityWithMapAsObject() throws JSONException {
794+
795+
Map<String, Object> map = new LinkedHashMap<>();
796+
map.put("foo", "bar");
797+
798+
EntityWithObject entity = new EntityWithObject();
799+
entity.setId("42");
800+
entity.setContent(map);
801+
802+
String expected = "{\n" + //
803+
" \"id\": \"42\",\n" + //
804+
" \"content\": {\n" + //
805+
" \"foo\": \"bar\"\n" + //
806+
" }\n" + //
807+
"}\n"; //
808+
809+
Document document = Document.create();
810+
811+
mappingElasticsearchConverter.write(entity, document);
812+
813+
assertEquals(expected, document.toJson(), false);
814+
}
815+
792816
private String pointTemplate(String name, Point point) {
793817
return String.format(Locale.ENGLISH, "\"%s\":{\"lat\":%.1f,\"lon\":%.1f}", name, point.getX(), point.getY());
794818
}
@@ -1016,4 +1040,10 @@ static class GeoPointListEntity {
10161040
@Id String id;
10171041
List<GeoPoint> locations;
10181042
}
1043+
1044+
@Data
1045+
static class EntityWithObject {
1046+
@Id private String id;
1047+
private Object content;
1048+
}
10191049
}

0 commit comments

Comments
 (0)