mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-07-06 18:52:11 +00:00
DATAES-561 - Reuse ObjectMapper in ElasticsearchEntityMapper
Original pull request: #269
This commit is contained in:
parent
dff7d4e11b
commit
676567910d
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectReader;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -56,6 +58,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
* {@link ElasticsearchPersistentEntity metadata}.
|
* {@link ElasticsearchPersistentEntity metadata}.
|
||||||
*
|
*
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchEntityMapper implements
|
public class ElasticsearchEntityMapper implements
|
||||||
@ -65,6 +68,8 @@ public class ElasticsearchEntityMapper implements
|
|||||||
|
|
||||||
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
||||||
private final GenericConversionService conversionService;
|
private final GenericConversionService conversionService;
|
||||||
|
private final ObjectReader objectReader;
|
||||||
|
private final ObjectWriter objectWriter;
|
||||||
|
|
||||||
private CustomConversions conversions = new ElasticsearchCustomConversions(Collections.emptyList());
|
private CustomConversions conversions = new ElasticsearchCustomConversions(Collections.emptyList());
|
||||||
private EntityInstantiators instantiators = new EntityInstantiators();
|
private EntityInstantiators instantiators = new EntityInstantiators();
|
||||||
@ -78,6 +83,10 @@ public class ElasticsearchEntityMapper implements
|
|||||||
this.mappingContext = mappingContext;
|
this.mappingContext = mappingContext;
|
||||||
this.conversionService = conversionService != null ? conversionService : new DefaultConversionService();
|
this.conversionService = conversionService != null ? conversionService : new DefaultConversionService();
|
||||||
this.typeMapper = ElasticsearchTypeMapper.create(mappingContext);
|
this.typeMapper = ElasticsearchTypeMapper.create(mappingContext);
|
||||||
|
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
objectReader = objectMapper.readerFor(HashMap.class);
|
||||||
|
objectWriter = objectMapper.writer();
|
||||||
}
|
}
|
||||||
|
|
||||||
// --> GETTERS / SETTERS
|
// --> GETTERS / SETTERS
|
||||||
@ -543,12 +552,12 @@ public class ElasticsearchEntityMapper implements
|
|||||||
Map<String, Object> sink = new LinkedHashMap<>();
|
Map<String, Object> sink = new LinkedHashMap<>();
|
||||||
write(source, sink);
|
write(source, sink);
|
||||||
|
|
||||||
return new ObjectMapper().writeValueAsString(sink);
|
return objectWriter.writeValueAsString(sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T mapToObject(String source, Class<T> clazz) throws IOException {
|
public <T> T mapToObject(String source, Class<T> clazz) throws IOException {
|
||||||
return read(clazz, new ObjectMapper().readerFor(HashMap.class).readValue(source));
|
return read(clazz, objectReader.readValue(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --> PRIVATE HELPERS
|
// --> PRIVATE HELPERS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user