diff --git a/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java b/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java
index 40c53096b..2bf5acf90 100644
--- a/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java
+++ b/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java
@@ -478,7 +478,7 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper
ElasticsearchPersistentProperty idProperty = persistentEntity.getIdProperty();
// Only deal with text because ES generated Ids are strings!
- if (indexedObjectInformation.getId() != null && idProperty != null
+ if (indexedObjectInformation.getId() != null && idProperty != null && idProperty.isWritable()
&& idProperty.getType().isAssignableFrom(String.class)) {
propertyAccessor.setProperty(idProperty, indexedObjectInformation.getId());
}
diff --git a/src/main/java/org/springframework/data/elasticsearch/core/AbstractReactiveElasticsearchTemplate.java b/src/main/java/org/springframework/data/elasticsearch/core/AbstractReactiveElasticsearchTemplate.java
index bd2974ffd..7c348a19a 100644
--- a/src/main/java/org/springframework/data/elasticsearch/core/AbstractReactiveElasticsearchTemplate.java
+++ b/src/main/java/org/springframework/data/elasticsearch/core/AbstractReactiveElasticsearchTemplate.java
@@ -259,7 +259,7 @@ abstract public class AbstractReactiveElasticsearchTemplate
ElasticsearchPersistentProperty idProperty = persistentEntity.getIdProperty();
// Only deal with text because ES generated Ids are strings!
- if (indexedObjectInformation.getId() != null && idProperty != null
+ if (indexedObjectInformation.getId() != null && idProperty != null && idProperty.isWritable()
&& idProperty.getType().isAssignableFrom(String.class)) {
propertyAccessor.setProperty(idProperty, indexedObjectInformation.getId());
}
diff --git a/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java b/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java
index 96539c2fc..d03c3056a 100644
--- a/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java
+++ b/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java
@@ -15,12 +15,6 @@
*/
package org.springframework.data.elasticsearch.core.convert;
-import java.time.temporal.TemporalAccessor;
-import java.util.*;
-import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.stream.Collectors;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
@@ -53,7 +47,16 @@ import org.springframework.data.mapping.Parameter;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.SimplePropertyHandler;
import org.springframework.data.mapping.context.MappingContext;
-import org.springframework.data.mapping.model.*;
+import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
+import org.springframework.data.mapping.model.DefaultSpELExpressionEvaluator;
+import org.springframework.data.mapping.model.EntityInstantiator;
+import org.springframework.data.mapping.model.EntityInstantiators;
+import org.springframework.data.mapping.model.ParameterValueProvider;
+import org.springframework.data.mapping.model.PersistentEntityParameterValueProvider;
+import org.springframework.data.mapping.model.PropertyValueProvider;
+import org.springframework.data.mapping.model.SpELContext;
+import org.springframework.data.mapping.model.SpELExpressionEvaluator;
+import org.springframework.data.mapping.model.SpELExpressionParameterValueProvider;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.format.datetime.DateFormatterRegistrar;
@@ -63,6 +66,12 @@ import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
+import java.time.temporal.TemporalAccessor;
+import java.util.*;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
/**
* Elasticsearch specific {@link org.springframework.data.convert.EntityConverter} implementation based on domain type
* {@link ElasticsearchPersistentEntity metadata}.
@@ -83,12 +92,15 @@ import org.springframework.util.ObjectUtils;
public class MappingElasticsearchConverter
implements ElasticsearchConverter, ApplicationContextAware, InitializingBean {
- private static final String INCOMPATIBLE_TYPES = "Cannot convert %1$s of type %2$s into an instance of %3$s! Implement a custom Converter<%2$s, %3$s> and register it with the CustomConversions.";
- private static final String INVALID_TYPE_TO_READ = "Expected to read Document %s into type %s but didn't find a PersistentEntity for the latter!";
+ private static final String INCOMPATIBLE_TYPES =
+ "Cannot convert %1$s of type %2$s into an instance of %3$s! Implement a custom Converter<%2$s, %3$s> and register it with the CustomConversions.";
+ private static final String INVALID_TYPE_TO_READ =
+ "Expected to read Document %s into type %s but didn't find a PersistentEntity for the latter!";
private static final Log LOGGER = LogFactory.getLog(MappingElasticsearchConverter.class);
- private final MappingContext extends ElasticsearchPersistentEntity>, ElasticsearchPersistentProperty> mappingContext;
+ private final MappingContext extends ElasticsearchPersistentEntity>, ElasticsearchPersistentProperty>
+ mappingContext;
private final GenericConversionService conversionService;
private CustomConversions conversions = new ElasticsearchCustomConversions(Collections.emptyList());
private final SpELContext spELContext = new SpELContext(new MapAccessor());
@@ -130,8 +142,8 @@ public class MappingElasticsearchConverter
}
/**
- * Set the {@link CustomConversions} to be applied during the mapping process.
- * Conversions are registered after {@link #afterPropertiesSet() bean initialization}.
+ * Set the {@link CustomConversions} to be applied during the mapping process.
Conversions are registered
+ * after {@link #afterPropertiesSet() bean initialization}.
*
* @param conversions must not be {@literal null}.
*/
@@ -157,7 +169,8 @@ public class MappingElasticsearchConverter
@Override
public R read(Class type, Document source) {
- Reader reader = new Reader(mappingContext, conversionService, conversions, typeMapper, spELContext, instantiators);
+ Reader reader =
+ new Reader(mappingContext, conversionService, conversions, typeMapper, spELContext, instantiators);
return reader.read(type, source);
}
@@ -175,7 +188,8 @@ public class MappingElasticsearchConverter
*/
private static class Base {
- protected final MappingContext extends ElasticsearchPersistentEntity>, ElasticsearchPersistentProperty> mappingContext;
+ protected final MappingContext extends ElasticsearchPersistentEntity>, ElasticsearchPersistentProperty>
+ mappingContext;
protected final ElasticsearchTypeMapper typeMapper;
protected final GenericConversionService conversionService;
protected final CustomConversions conversions;
@@ -183,7 +197,8 @@ public class MappingElasticsearchConverter
private Base(
MappingContext extends ElasticsearchPersistentEntity>, ElasticsearchPersistentProperty> mappingContext,
- GenericConversionService conversionService, CustomConversions conversions, ElasticsearchTypeMapper typeMapper) {
+ GenericConversionService conversionService, CustomConversions conversions,
+ ElasticsearchTypeMapper typeMapper) {
this.mappingContext = mappingContext;
this.conversionService = conversionService;
this.conversions = conversions;
@@ -202,7 +217,8 @@ public class MappingElasticsearchConverter
public Reader(
MappingContext extends ElasticsearchPersistentEntity>, ElasticsearchPersistentProperty> mappingContext,
- GenericConversionService conversionService, CustomConversions conversions, ElasticsearchTypeMapper typeMapper,
+ GenericConversionService conversionService, CustomConversions conversions,
+ ElasticsearchTypeMapper typeMapper,
SpELContext spELContext, EntityInstantiators instantiators) {
super(mappingContext, conversionService, conversions, typeMapper);
@@ -292,7 +308,8 @@ public class MappingElasticsearchConverter
map.put(key, read(defaultedValueType, (Map) value));
} else if (value instanceof List) {
map.put(key,
- readCollectionOrArray(valueType != null ? valueType : ClassTypeInformation.LIST, (List