Skip to content

Commit 877de9c

Browse files
committed
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 #1676. See #1675.
1 parent d18b5af commit 877de9c

File tree

4 files changed

+536
-257
lines changed

4 files changed

+536
-257
lines changed

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

+18-1
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)