mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-30 08:42:10 +00:00
Created Custom ObjectMapper (markdown)
parent
1469a10734
commit
d6f01f6120
36
Custom-ObjectMapper.md
Normal file
36
Custom-ObjectMapper.md
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
How to use custom ObjectMapper?
|
||||||
|
|
||||||
|
1. Create new Class and implement Interface EntityMapper
|
||||||
|
```
|
||||||
|
public class CustomEntityMapper implements EntityMapper {
|
||||||
|
|
||||||
|
public CustomEntityMapper(){
|
||||||
|
//custom configuration/implementation (e.g. FasterXML/jackson)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String mapToString(Object object) throws IOException {
|
||||||
|
//mapping Object to String
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T mapToObject(String source, Class<T> clazz) throws IOException {
|
||||||
|
//mapping String to Object
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
2. Define new bean and inject it into ElasticsearchTemplate
|
||||||
|
```
|
||||||
|
<bean name="elasticsearchTemplate"
|
||||||
|
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
||||||
|
<constructor-arg name="client" ref="client"/>
|
||||||
|
<constructor-arg name="entityMapper" ref="entityMapper"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean name="entityMapper" class="org.springframework.data.elasticsearch.core.CustomEntityMapper"/>
|
||||||
|
```
|
||||||
|
3. Done
|
||||||
|
|
||||||
|
Default implementation for EntityMapper used in project can be found here https://github.com/spring-projects/spring-data-elasticsearch/blob/master/src/main/java/org/springframework/data/elasticsearch/core/DefaultEntityMapper.java
|
Loading…
x
Reference in New Issue
Block a user