Skip to content

Commit 0c15eef

Browse files
authored
DATAES-740 - Adapt to spring-data-commons changes.
Original PR: spring-projects#386
1 parent 936de20 commit 0c15eef

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

src/main/java/org/springframework/data/elasticsearch/config/ElasticsearchConfigurationSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public SimpleElasticsearchMappingContext elasticsearchMappingContext() {
7676
*/
7777
@Bean
7878
public ElasticsearchCustomConversions elasticsearchCustomConversions() {
79-
return new ElasticsearchCustomConversions(Collections.emptyList());
79+
return ElasticsearchCustomConversions.of(Collections.emptyList());
8080
}
8181

8282
/**

src/main/java/org/springframework/data/elasticsearch/core/convert/ElasticsearchCustomConversions.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
public class ElasticsearchCustomConversions extends CustomConversions {
4040

4141
private static final StoreConversions STORE_CONVERSIONS;
42-
private static final List<Object> STORE_CONVERTERS;
42+
private static final List<Converter<?, ?>> STORE_CONVERTERS;
4343

4444
static {
4545

46-
List<Object> converters = new ArrayList<>(GeoConverters.getConvertersToRegister());
46+
List<Converter<?, ?>> converters = new ArrayList<>();
4747
converters.add(StringToUUIDConverter.INSTANCE);
4848
converters.add(UUIDToStringConverter.INSTANCE);
4949
converters.add(BigDecimalToDoubleConverter.INSTANCE);
@@ -58,8 +58,14 @@ public class ElasticsearchCustomConversions extends CustomConversions {
5858
*
5959
* @param converters must not be {@literal null}.
6060
*/
61-
public ElasticsearchCustomConversions(Collection<?> converters) {
62-
super(STORE_CONVERSIONS, converters);
61+
public static ElasticsearchCustomConversions of(Collection<Converter<?, ?>> converters) {
62+
List<Converter<?, ?>> userConverters = new ArrayList<>(GeoConverters.getConvertersToRegister());
63+
userConverters.addAll(converters);
64+
return new ElasticsearchCustomConversions(STORE_CONVERSIONS, userConverters);
65+
}
66+
67+
private ElasticsearchCustomConversions(StoreConversions storeConversions, Collection<?> converters) {
68+
super(storeConversions, converters);
6369
}
6470

6571
/**

src/main/java/org/springframework/data/elasticsearch/core/convert/GeoConverters.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131
* Set of {@link Converter converters} specific to Elasticsearch Geo types.
3232
*
3333
* @author Christoph Strobl
34+
* @author Peter-Josef Meisch
3435
* @since 3.2
3536
*/
3637
class GeoConverters {
3738

38-
static Collection<Object> getConvertersToRegister() {
39+
static Collection<Converter<?, ?>> getConvertersToRegister() {
3940

4041
return Arrays.asList(PointToMapConverter.INSTANCE, MapToPointConverter.INSTANCE, GeoPointToMapConverter.INSTANCE,
4142
MapToGeoPointConverter.INSTANCE);
@@ -50,7 +51,7 @@ enum PointToMapConverter implements Converter<Point, Map<String, Object>> {
5051
INSTANCE;
5152

5253
@Override
53-
public Map convert(Point source) {
54+
public Map<String, Object> convert(Point source) {
5455

5556
Map<String, Object> target = new LinkedHashMap<>();
5657
target.put("lat", source.getX());
@@ -68,7 +69,7 @@ enum GeoPointToMapConverter implements Converter<GeoPoint, Map<String, Object>>
6869
INSTANCE;
6970

7071
@Override
71-
public Map convert(GeoPoint source) {
72+
public Map<String, Object> convert(GeoPoint source) {
7273
Map<String, Object> target = new LinkedHashMap<>();
7374
target.put("lat", source.getLat());
7475
target.put("lon", source.getLon());
@@ -85,7 +86,7 @@ enum MapToPointConverter implements Converter<Map<String, Object>, Point> {
8586
INSTANCE;
8687

8788
@Override
88-
public Point convert(Map source) {
89+
public Point convert(Map<String, Object> source) {
8990
Double x = NumberUtils.convertNumberToTargetClass((Number) source.get("lat"), Double.class);
9091
Double y = NumberUtils.convertNumberToTargetClass((Number) source.get("lon"), Double.class);
9192

@@ -102,7 +103,7 @@ enum MapToGeoPointConverter implements Converter<Map<String, Object>, GeoPoint>
102103
INSTANCE;
103104

104105
@Override
105-
public GeoPoint convert(Map source) {
106+
public GeoPoint convert(Map<String, Object> source) {
106107
Double x = NumberUtils.convertNumberToTargetClass((Number) source.get("lat"), Double.class);
107108
Double y = NumberUtils.convertNumberToTargetClass((Number) source.get("lon"), Double.class);
108109

src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class MappingElasticsearchConverter
8585
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
8686
private final GenericConversionService conversionService;
8787

88-
private CustomConversions conversions = new ElasticsearchCustomConversions(Collections.emptyList());
88+
private CustomConversions conversions = ElasticsearchCustomConversions.of(Collections.emptyList());
8989
private EntityInstantiators instantiators = new EntityInstantiators();
9090

9191
private ElasticsearchTypeMapper typeMapper;

src/test/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverterUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void init() {
108108

109109
mappingElasticsearchConverter = new MappingElasticsearchConverter(mappingContext, new GenericConversionService());
110110
mappingElasticsearchConverter.setConversions(
111-
new ElasticsearchCustomConversions(Arrays.asList(new ShotGunToMapConverter(), new MapToShotGunConverter())));
111+
ElasticsearchCustomConversions.of(Arrays.asList(new ShotGunToMapConverter(), new MapToShotGunConverter())));
112112
mappingElasticsearchConverter.afterPropertiesSet();
113113

114114
sarahConnor = new Person();

0 commit comments

Comments
 (0)