mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-31 09:12:11 +00:00
Fix MappingElasticsearchConverter conversion from Document into Map<String, Object>.
Original PR: #436
This commit is contained in:
parent
16d8cc22d1
commit
5019793f17
@ -70,6 +70,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Peter-Josef Meisch
|
||||
* @author Mark Paluch
|
||||
* @author Roman Puchkovskiy
|
||||
* @author Konrad Kurdej
|
||||
* @since 3.2
|
||||
*/
|
||||
public class MappingElasticsearchConverter
|
||||
@ -319,7 +320,7 @@ public class MappingElasticsearchConverter
|
||||
target.put(entryKey, null);
|
||||
} else if (isSimpleType(entryValue)) {
|
||||
target.put(entryKey,
|
||||
readSimpleValue(entryValue, targetType.isMap() ? targetType.getComponentType() : targetType));
|
||||
readSimpleValue(entryValue, targetType.isMap() ? targetType.getMapValueType() : targetType));
|
||||
} else {
|
||||
|
||||
ElasticsearchPersistentEntity<?> targetEntity = computeGenericValueTypeForRead(property, entryValue);
|
||||
|
@ -68,6 +68,7 @@ import org.springframework.lang.Nullable;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @author Peter-Josef Meisch
|
||||
* @author Konrad Kurdej
|
||||
*/
|
||||
public class MappingElasticsearchConverterUnitTests {
|
||||
|
||||
@ -662,6 +663,20 @@ public class MappingElasticsearchConverterUnitTests {
|
||||
assertThat(notification.params.get("content")).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAES-795
|
||||
void readGenericMapWithSimpleTypes() {
|
||||
Map<String, Object> mapWithSimpleValues = new HashMap<>();
|
||||
mapWithSimpleValues.put("int", 1);
|
||||
mapWithSimpleValues.put("string", "string");
|
||||
mapWithSimpleValues.put("boolean", true);
|
||||
|
||||
Document document = Document.create();
|
||||
document.put("schemaLessObject", mapWithSimpleValues);
|
||||
|
||||
SchemaLessObjectWrapper wrapper = mappingElasticsearchConverter.read(SchemaLessObjectWrapper.class, document);
|
||||
assertThat(wrapper.getSchemaLessObject()).isEqualTo(mapWithSimpleValues);
|
||||
}
|
||||
|
||||
private String pointTemplate(String name, Point point) {
|
||||
return String.format(Locale.ENGLISH, "\"%s\":{\"lat\":%.1f,\"lon\":%.1f}", name, point.getX(), point.getY());
|
||||
}
|
||||
@ -860,4 +875,12 @@ public class MappingElasticsearchConverterUnitTests {
|
||||
|
||||
@GeoPointField private double[] pointD;
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
static class SchemaLessObjectWrapper {
|
||||
|
||||
private Map<String, Object> schemaLessObject;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user