Skip to content

Commit 9bab588

Browse files
committed
Rollback converters to Map
See #1675.
1 parent d4c908e commit 9bab588

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

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

+29-30
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.springframework.core.convert.converter.Converter;
2727
import org.springframework.data.convert.ReadingConverter;
2828
import org.springframework.data.convert.WritingConverter;
29-
import org.springframework.data.elasticsearch.core.document.Document;
3029
import org.springframework.data.elasticsearch.core.geo.GeoJson;
3130
import org.springframework.data.elasticsearch.core.geo.GeoJsonGeometryCollection;
3231
import org.springframework.data.elasticsearch.core.geo.GeoJsonLineString;
@@ -68,14 +67,14 @@ public class GeoConverters {
6867
* {@link Converter} to write a {@link Point} to {@link Map} using {@code lat/long} properties.
6968
*/
7069
@WritingConverter
71-
public enum PointToMapConverter implements Converter<Point, Document> {
70+
public enum PointToMapConverter implements Converter<Point, Map<String, Object>> {
7271

7372
INSTANCE;
7473

7574
@Override
76-
public Document convert(Point source) {
75+
public Map<String, Object> convert(Point source) {
7776

78-
Document target = Document.create();
77+
Map<String, Object> target = new LinkedHashMap<>();
7978
target.put("lat", source.getY());
8079
target.put("lon", source.getX());
8180
return target;
@@ -105,13 +104,13 @@ public Point convert(Map<String, Object> source) {
105104
* {@link Converter} to write a {@link GeoPoint} to {@link Map} using {@code lat/long} properties.
106105
*/
107106
@WritingConverter
108-
public enum GeoPointToMapConverter implements Converter<GeoPoint, Document> {
107+
public enum GeoPointToMapConverter implements Converter<GeoPoint, Map<String, Object>> {
109108

110109
INSTANCE;
111110

112111
@Override
113-
public Document convert(GeoPoint source) {
114-
Document target = Document.create();
112+
public Map<String, Object> convert(GeoPoint source) {
113+
Map<String, Object> target = new LinkedHashMap<>();
115114
target.put("lat", source.getLat());
116115
target.put("lon", source.getLon());
117116
return target;
@@ -136,12 +135,12 @@ public GeoPoint convert(Map<String, Object> source) {
136135

137136
// region GeoJson
138137
@WritingConverter
139-
public enum GeoJsonToMapConverter implements Converter<GeoJson<? extends Iterable<?>>, Document> {
138+
public enum GeoJsonToMapConverter implements Converter<GeoJson<? extends Iterable<?>>, Map<String, Object>> {
140139

141140
INSTANCE;
142141

143142
@Override
144-
public Document convert(GeoJson<? extends Iterable<?>> source) {
143+
public Map<String, Object> convert(GeoJson<? extends Iterable<?>> source) {
145144
if (source instanceof GeoJsonPoint) {
146145
return GeoJsonPointToMapConverter.INSTANCE.convert((GeoJsonPoint) source);
147146
} else if (source instanceof GeoJsonMultiPoint) {
@@ -196,13 +195,13 @@ public GeoJson<? extends Iterable<?>> convert(Map<String, Object> source) {
196195

197196
// region GeoJsonPoint
198197
@WritingConverter
199-
public enum GeoJsonPointToMapConverter implements Converter<GeoJsonPoint, Document> {
198+
public enum GeoJsonPointToMapConverter implements Converter<GeoJsonPoint, Map<String, Object>> {
200199

201200
INSTANCE;
202201

203202
@Override
204-
public Document convert(GeoJsonPoint geoJsonPoint) {
205-
Document map = Document.create();
203+
public Map<String, Object> convert(GeoJsonPoint geoJsonPoint) {
204+
Map<String, Object> map = new LinkedHashMap<>();
206205
map.put("type", geoJsonPoint.getType());
207206
map.put("coordinates", geoJsonPoint.getCoordinates());
208207
return map;
@@ -234,13 +233,13 @@ public GeoJsonPoint convert(Map<String, Object> source) {
234233

235234
// region GeoJsonMultiPoint
236235
@WritingConverter
237-
public enum GeoJsonMultiPointToMapConverter implements Converter<GeoJsonMultiPoint, Document> {
236+
public enum GeoJsonMultiPointToMapConverter implements Converter<GeoJsonMultiPoint, Map<String, Object>> {
238237

239238
INSTANCE;
240239

241240
@Override
242-
public Document convert(GeoJsonMultiPoint geoJsonMultiPoint) {
243-
Document map = Document.create();
241+
public Map<String, Object> convert(GeoJsonMultiPoint geoJsonMultiPoint) {
242+
Map<String, Object> map = new LinkedHashMap<>();
244243
map.put("type", geoJsonMultiPoint.getType());
245244
map.put("coordinates", pointsToCoordinates(geoJsonMultiPoint.getCoordinates()));
246245
return map;
@@ -269,13 +268,13 @@ public GeoJsonMultiPoint convert(Map<String, Object> source) {
269268

270269
// region GeoJsonLineString
271270
@WritingConverter
272-
public enum GeoJsonLineStringToMapConverter implements Converter<GeoJsonLineString, Document> {
271+
public enum GeoJsonLineStringToMapConverter implements Converter<GeoJsonLineString, Map<String, Object>> {
273272

274273
INSTANCE;
275274

276275
@Override
277-
public Document convert(GeoJsonLineString geoJsonLineString) {
278-
Document map = Document.create();
276+
public Map<String, Object> convert(GeoJsonLineString geoJsonLineString) {
277+
Map<String, Object> map = new LinkedHashMap<>();
279278
map.put("type", geoJsonLineString.getType());
280279
map.put("coordinates", pointsToCoordinates(geoJsonLineString.getCoordinates()));
281280
return map;
@@ -304,12 +303,12 @@ public GeoJsonLineString convert(Map<String, Object> source) {
304303

305304
// region GeoJsonMultiLineString
306305
@WritingConverter
307-
public enum GeoJsonMultiLineStringToMapConverter implements Converter<GeoJsonMultiLineString, Document> {
306+
public enum GeoJsonMultiLineStringToMapConverter implements Converter<GeoJsonMultiLineString, Map<String, Object>> {
308307

309308
INSTANCE;
310309

311310
@Override
312-
public Document convert(GeoJsonMultiLineString source) {
311+
public Map<String, Object> convert(GeoJsonMultiLineString source) {
313312
return geoJsonLinesStringsToMap(source.getType(), source.getCoordinates());
314313
}
315314
}
@@ -332,12 +331,12 @@ public GeoJsonMultiLineString convert(Map<String, Object> source) {
332331

333332
// region GeoJsonPolygon
334333
@WritingConverter
335-
public enum GeoJsonPolygonToMapConverter implements Converter<GeoJsonPolygon, Document> {
334+
public enum GeoJsonPolygonToMapConverter implements Converter<GeoJsonPolygon, Map<String, Object>> {
336335

337336
INSTANCE;
338337

339338
@Override
340-
public Document convert(GeoJsonPolygon source) {
339+
public Map<String, Object> convert(GeoJsonPolygon source) {
341340
return geoJsonLinesStringsToMap(source.getType(), source.getCoordinates());
342341
}
343342
}
@@ -370,9 +369,9 @@ public enum GeoJsonMultiPolygonToMapConverter implements Converter<GeoJsonMultiP
370369
INSTANCE;
371370

372371
@Override
373-
public Document convert(GeoJsonMultiPolygon source) {
372+
public Map<String, Object> convert(GeoJsonMultiPolygon source) {
374373

375-
Document map = Document.create();
374+
Map<String, Object> map = new LinkedHashMap<>();
376375
map.put("type", source.getType());
377376

378377
List<Object> coordinates = source.getCoordinates().stream() //
@@ -401,7 +400,7 @@ public GeoJsonMultiPolygon convert(Map<String, Object> source) {
401400
Assert.isTrue(coordinates instanceof List, "coordinates must be a List");
402401

403402
List<GeoJsonPolygon> geoJsonPolygons = ((List<?>) coordinates).stream().map(it -> {
404-
Document map = Document.create();
403+
Map<String, Object> map = new LinkedHashMap<>();
405404
map.put("type", GeoJsonPolygon.TYPE);
406405
map.put("coordinates", it);
407406
return map;
@@ -415,14 +414,14 @@ public GeoJsonMultiPolygon convert(Map<String, Object> source) {
415414
// region GeoJsonGeometryCollection
416415
@WritingConverter
417416
public enum GeoJsonGeometryCollectionToMapConverter
418-
implements Converter<GeoJsonGeometryCollection, Document> {
417+
implements Converter<GeoJsonGeometryCollection, Map<String, Object>> {
419418

420419
INSTANCE;
421420

422421
@Override
423-
public Document convert(GeoJsonGeometryCollection source) {
422+
public Map<String, Object> convert(GeoJsonGeometryCollection source) {
424423

425-
Document map = Document.create();
424+
Map<String, Object> map = new LinkedHashMap<>();
426425
map.put("type", source.getType());
427426
List<Map<String, Object>> geometries = source.getGeometries().stream()
428427
.map(GeoJsonToMapConverter.INSTANCE::convert).collect(Collectors.toList());
@@ -485,8 +484,8 @@ private static List<Point> coordinatesToPoints(List<List<Number>> pointList) {
485484
}).collect(Collectors.toList());
486485
}
487486

488-
private static Document geoJsonLinesStringsToMap(String type, List<GeoJsonLineString> lineStrings) {
489-
Document map = Document.create();
487+
private static Map<String, Object> geoJsonLinesStringsToMap(String type, List<GeoJsonLineString> lineStrings) {
488+
Map<String, Object> map = new LinkedHashMap<>();
490489
map.put("type", type);
491490
List<List<List<Double>>> coordinates = lineStrings.stream()
492491
.map(it -> GeoConverters.pointsToCoordinates(it.getCoordinates())).collect(Collectors.toList());

0 commit comments

Comments
 (0)