mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-14 16:12:11 +00:00
DATAES-865 - Polishing.
(cherry picked from commit 92f16846abaf7266de1e9669aadd3bd24f5b64a1)
This commit is contained in:
parent
d2df9e7f4c
commit
ae94120d91
@ -596,7 +596,9 @@ public class MappingElasticsearchConverter
|
|||||||
Map<Object, Object> target = new LinkedHashMap<>();
|
Map<Object, Object> target = new LinkedHashMap<>();
|
||||||
Streamable<Entry<String, Object>> mapSource = Streamable.of(value.entrySet());
|
Streamable<Entry<String, Object>> mapSource = Streamable.of(value.entrySet());
|
||||||
|
|
||||||
if (typeHint.getActualType() != null && !typeHint.getActualType().getType().equals(Object.class)
|
TypeInformation<?> actualType = typeHint.getActualType();
|
||||||
|
|
||||||
|
if (actualType != null && !actualType.getType().equals(Object.class)
|
||||||
&& isSimpleType(typeHint.getMapValueType().getType())) {
|
&& isSimpleType(typeHint.getMapValueType().getType())) {
|
||||||
mapSource.forEach(it -> {
|
mapSource.forEach(it -> {
|
||||||
|
|
||||||
|
@ -789,6 +789,30 @@ public class MappingElasticsearchConverterUnitTests {
|
|||||||
assertThat(entity.locations).containsExactly(new GeoPoint(12.34, 23.45), new GeoPoint(34.56, 45.67));
|
assertThat(entity.locations).containsExactly(new GeoPoint(12.34, 23.45), new GeoPoint(34.56, 45.67));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // DATAES-865
|
||||||
|
void shouldWriteEntityWithMapAsObject() throws JSONException {
|
||||||
|
|
||||||
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
|
map.put("foo", "bar");
|
||||||
|
|
||||||
|
EntityWithObject entity = new EntityWithObject();
|
||||||
|
entity.setId("42");
|
||||||
|
entity.setContent(map);
|
||||||
|
|
||||||
|
String expected = "{\n" + //
|
||||||
|
" \"id\": \"42\",\n" + //
|
||||||
|
" \"content\": {\n" + //
|
||||||
|
" \"foo\": \"bar\"\n" + //
|
||||||
|
" }\n" + //
|
||||||
|
"}\n"; //
|
||||||
|
|
||||||
|
Document document = Document.create();
|
||||||
|
|
||||||
|
mappingElasticsearchConverter.write(entity, document);
|
||||||
|
|
||||||
|
assertEquals(expected, document.toJson(), false);
|
||||||
|
}
|
||||||
|
|
||||||
private String pointTemplate(String name, Point point) {
|
private String pointTemplate(String name, Point point) {
|
||||||
return String.format(Locale.ENGLISH, "\"%s\":{\"lat\":%.1f,\"lon\":%.1f}", name, point.getX(), point.getY());
|
return String.format(Locale.ENGLISH, "\"%s\":{\"lat\":%.1f,\"lon\":%.1f}", name, point.getX(), point.getY());
|
||||||
}
|
}
|
||||||
@ -1016,4 +1040,10 @@ public class MappingElasticsearchConverterUnitTests {
|
|||||||
@Id String id;
|
@Id String id;
|
||||||
List<GeoPoint> locations;
|
List<GeoPoint> locations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
static class EntityWithObject {
|
||||||
|
@Id private String id;
|
||||||
|
private Object content;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user