mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-28 14:52:20 +00:00
parent
936de20421
commit
0c15eef858
@ -76,7 +76,7 @@ public class ElasticsearchConfigurationSupport {
|
|||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public ElasticsearchCustomConversions elasticsearchCustomConversions() {
|
public ElasticsearchCustomConversions elasticsearchCustomConversions() {
|
||||||
return new ElasticsearchCustomConversions(Collections.emptyList());
|
return ElasticsearchCustomConversions.of(Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,11 +39,11 @@ import org.springframework.util.NumberUtils;
|
|||||||
public class ElasticsearchCustomConversions extends CustomConversions {
|
public class ElasticsearchCustomConversions extends CustomConversions {
|
||||||
|
|
||||||
private static final StoreConversions STORE_CONVERSIONS;
|
private static final StoreConversions STORE_CONVERSIONS;
|
||||||
private static final List<Object> STORE_CONVERTERS;
|
private static final List<Converter<?, ?>> STORE_CONVERTERS;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
||||||
List<Object> converters = new ArrayList<>(GeoConverters.getConvertersToRegister());
|
List<Converter<?, ?>> converters = new ArrayList<>();
|
||||||
converters.add(StringToUUIDConverter.INSTANCE);
|
converters.add(StringToUUIDConverter.INSTANCE);
|
||||||
converters.add(UUIDToStringConverter.INSTANCE);
|
converters.add(UUIDToStringConverter.INSTANCE);
|
||||||
converters.add(BigDecimalToDoubleConverter.INSTANCE);
|
converters.add(BigDecimalToDoubleConverter.INSTANCE);
|
||||||
@ -58,8 +58,14 @@ public class ElasticsearchCustomConversions extends CustomConversions {
|
|||||||
*
|
*
|
||||||
* @param converters must not be {@literal null}.
|
* @param converters must not be {@literal null}.
|
||||||
*/
|
*/
|
||||||
public ElasticsearchCustomConversions(Collection<?> converters) {
|
public static ElasticsearchCustomConversions of(Collection<Converter<?, ?>> converters) {
|
||||||
super(STORE_CONVERSIONS, converters);
|
List<Converter<?, ?>> userConverters = new ArrayList<>(GeoConverters.getConvertersToRegister());
|
||||||
|
userConverters.addAll(converters);
|
||||||
|
return new ElasticsearchCustomConversions(STORE_CONVERSIONS, userConverters);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ElasticsearchCustomConversions(StoreConversions storeConversions, Collection<?> converters) {
|
||||||
|
super(storeConversions, converters);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,11 +31,12 @@ import org.springframework.util.NumberUtils;
|
|||||||
* Set of {@link Converter converters} specific to Elasticsearch Geo types.
|
* Set of {@link Converter converters} specific to Elasticsearch Geo types.
|
||||||
*
|
*
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
class GeoConverters {
|
class GeoConverters {
|
||||||
|
|
||||||
static Collection<Object> getConvertersToRegister() {
|
static Collection<Converter<?, ?>> getConvertersToRegister() {
|
||||||
|
|
||||||
return Arrays.asList(PointToMapConverter.INSTANCE, MapToPointConverter.INSTANCE, GeoPointToMapConverter.INSTANCE,
|
return Arrays.asList(PointToMapConverter.INSTANCE, MapToPointConverter.INSTANCE, GeoPointToMapConverter.INSTANCE,
|
||||||
MapToGeoPointConverter.INSTANCE);
|
MapToGeoPointConverter.INSTANCE);
|
||||||
@ -50,7 +51,7 @@ class GeoConverters {
|
|||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map convert(Point source) {
|
public Map<String, Object> convert(Point source) {
|
||||||
|
|
||||||
Map<String, Object> target = new LinkedHashMap<>();
|
Map<String, Object> target = new LinkedHashMap<>();
|
||||||
target.put("lat", source.getX());
|
target.put("lat", source.getX());
|
||||||
@ -68,7 +69,7 @@ class GeoConverters {
|
|||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map convert(GeoPoint source) {
|
public Map<String, Object> convert(GeoPoint source) {
|
||||||
Map<String, Object> target = new LinkedHashMap<>();
|
Map<String, Object> target = new LinkedHashMap<>();
|
||||||
target.put("lat", source.getLat());
|
target.put("lat", source.getLat());
|
||||||
target.put("lon", source.getLon());
|
target.put("lon", source.getLon());
|
||||||
@ -85,7 +86,7 @@ class GeoConverters {
|
|||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Point convert(Map source) {
|
public Point convert(Map<String, Object> source) {
|
||||||
Double x = NumberUtils.convertNumberToTargetClass((Number) source.get("lat"), Double.class);
|
Double x = NumberUtils.convertNumberToTargetClass((Number) source.get("lat"), Double.class);
|
||||||
Double y = NumberUtils.convertNumberToTargetClass((Number) source.get("lon"), Double.class);
|
Double y = NumberUtils.convertNumberToTargetClass((Number) source.get("lon"), Double.class);
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ class GeoConverters {
|
|||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint convert(Map source) {
|
public GeoPoint convert(Map<String, Object> source) {
|
||||||
Double x = NumberUtils.convertNumberToTargetClass((Number) source.get("lat"), Double.class);
|
Double x = NumberUtils.convertNumberToTargetClass((Number) source.get("lat"), Double.class);
|
||||||
Double y = NumberUtils.convertNumberToTargetClass((Number) source.get("lon"), Double.class);
|
Double y = NumberUtils.convertNumberToTargetClass((Number) source.get("lon"), Double.class);
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ public class MappingElasticsearchConverter
|
|||||||
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
||||||
private final GenericConversionService conversionService;
|
private final GenericConversionService conversionService;
|
||||||
|
|
||||||
private CustomConversions conversions = new ElasticsearchCustomConversions(Collections.emptyList());
|
private CustomConversions conversions = ElasticsearchCustomConversions.of(Collections.emptyList());
|
||||||
private EntityInstantiators instantiators = new EntityInstantiators();
|
private EntityInstantiators instantiators = new EntityInstantiators();
|
||||||
|
|
||||||
private ElasticsearchTypeMapper typeMapper;
|
private ElasticsearchTypeMapper typeMapper;
|
||||||
|
@ -108,7 +108,7 @@ public class MappingElasticsearchConverterUnitTests {
|
|||||||
|
|
||||||
mappingElasticsearchConverter = new MappingElasticsearchConverter(mappingContext, new GenericConversionService());
|
mappingElasticsearchConverter = new MappingElasticsearchConverter(mappingContext, new GenericConversionService());
|
||||||
mappingElasticsearchConverter.setConversions(
|
mappingElasticsearchConverter.setConversions(
|
||||||
new ElasticsearchCustomConversions(Arrays.asList(new ShotGunToMapConverter(), new MapToShotGunConverter())));
|
ElasticsearchCustomConversions.of(Arrays.asList(new ShotGunToMapConverter(), new MapToShotGunConverter())));
|
||||||
mappingElasticsearchConverter.afterPropertiesSet();
|
mappingElasticsearchConverter.afterPropertiesSet();
|
||||||
|
|
||||||
sarahConnor = new Person();
|
sarahConnor = new Person();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user