mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-31 09:12:11 +00:00
DATAES-865 - Polishing.
This commit is contained in:
parent
1de1aeb2c7
commit
92f16846ab
@ -596,7 +596,9 @@ public class MappingElasticsearchConverter
|
||||
Map<Object, Object> target = new LinkedHashMap<>();
|
||||
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())) {
|
||||
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));
|
||||
}
|
||||
|
||||
@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) {
|
||||
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;
|
||||
List<GeoPoint> locations;
|
||||
}
|
||||
|
||||
@Data
|
||||
static class EntityWithObject {
|
||||
@Id private String id;
|
||||
private Object content;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user