Skip to content

Commit a2baea7

Browse files
mp911desothawo
authored andcommitted
Refactor MappingElasticsearchConverter.
* Add support for SpEL expressions via @value. * Simplify readCollectionOrArray to consider properly nested lists and maps * Simplify readMap to allow reading generic maps and entities in maps. * Report a fallback TypeInformation in DefaultElasticsearchTypeMapper to properly convert nested maps. We now no longer rely on isSimpleType when writing Maps. This is the preparation to consider Map as simple type. Resolves spring-projects#1676. See spring-projects#1675. (cherry picked from commit 877de9c)
1 parent 63eebde commit a2baea7

File tree

3 files changed

+535
-257
lines changed

3 files changed

+535
-257
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.springframework.data.mapping.Alias;
2727
import org.springframework.data.mapping.PersistentEntity;
2828
import org.springframework.data.mapping.context.MappingContext;
29+
import org.springframework.data.util.ClassTypeInformation;
30+
import org.springframework.data.util.TypeInformation;
2931
import org.springframework.lang.Nullable;
3032

3133
/**
@@ -38,6 +40,9 @@
3840
public class DefaultElasticsearchTypeMapper extends DefaultTypeMapper<Map<String, Object>>
3941
implements ElasticsearchTypeMapper {
4042

43+
@SuppressWarnings("rawtypes") //
44+
private static final TypeInformation<Map> MAP_TYPE_INFO = ClassTypeInformation.from(Map.class);
45+
4146
private final @Nullable String typeKey;
4247

4348
public DefaultElasticsearchTypeMapper(@Nullable String typeKey) {
@@ -62,11 +67,23 @@ public DefaultElasticsearchTypeMapper(@Nullable String typeKey, TypeAliasAccesso
6267
this.typeKey = typeKey;
6368
}
6469

65-
@Override
70+
/*
71+
* (non-Javadoc)
72+
* @see org.springframework.data.mongodb.core.convert.MongoTypeMapper#isTypeKey(java.lang.String)
73+
*/
6674
public boolean isTypeKey(String key) {
6775
return typeKey != null && typeKey.equals(key);
6876
}
6977

78+
/*
79+
* (non-Javadoc)
80+
* @see org.springframework.data.convert.DefaultTypeMapper#getFallbackTypeFor(java.lang.Object)
81+
*/
82+
@Override
83+
protected TypeInformation<?> getFallbackTypeFor(Map<String, Object> source) {
84+
return MAP_TYPE_INFO;
85+
}
86+
7087
/**
7188
* {@link TypeAliasAccessor} to store aliases in a {@link Map}.
7289
*

0 commit comments

Comments
 (0)