15
15
*/
16
16
package org .springframework .data .elasticsearch .core ;
17
17
18
+ import com .fasterxml .jackson .databind .ObjectReader ;
19
+ import com .fasterxml .jackson .databind .ObjectWriter ;
18
20
import lombok .RequiredArgsConstructor ;
19
21
20
22
import java .io .IOException ;
56
58
* {@link ElasticsearchPersistentEntity metadata}.
57
59
*
58
60
* @author Christoph Strobl
61
+ * @author Peter-Josef Meisch
59
62
* @since 3.2
60
63
*/
61
64
public class ElasticsearchEntityMapper implements
@@ -65,6 +68,8 @@ public class ElasticsearchEntityMapper implements
65
68
66
69
private final MappingContext <? extends ElasticsearchPersistentEntity <?>, ElasticsearchPersistentProperty > mappingContext ;
67
70
private final GenericConversionService conversionService ;
71
+ private final ObjectReader objectReader ;
72
+ private final ObjectWriter objectWriter ;
68
73
69
74
private CustomConversions conversions = new ElasticsearchCustomConversions (Collections .emptyList ());
70
75
private EntityInstantiators instantiators = new EntityInstantiators ();
@@ -78,6 +83,10 @@ public ElasticsearchEntityMapper(
78
83
this .mappingContext = mappingContext ;
79
84
this .conversionService = conversionService != null ? conversionService : new DefaultConversionService ();
80
85
this .typeMapper = ElasticsearchTypeMapper .create (mappingContext );
86
+
87
+ ObjectMapper objectMapper = new ObjectMapper ();
88
+ objectReader = objectMapper .readerFor (HashMap .class );
89
+ objectWriter = objectMapper .writer ();
81
90
}
82
91
83
92
// --> GETTERS / SETTERS
@@ -543,12 +552,12 @@ public String mapToString(Object source) throws IOException {
543
552
Map <String , Object > sink = new LinkedHashMap <>();
544
553
write (source , sink );
545
554
546
- return new ObjectMapper () .writeValueAsString (sink );
555
+ return objectWriter .writeValueAsString (sink );
547
556
}
548
557
549
558
@ Override
550
559
public <T > T mapToObject (String source , Class <T > clazz ) throws IOException {
551
- return read (clazz , new ObjectMapper (). readerFor ( HashMap . class ) .readValue (source ));
560
+ return read (clazz , objectReader .readValue (source ));
552
561
}
553
562
554
563
// --> PRIVATE HELPERS
0 commit comments