26
26
import org .springframework .core .convert .converter .Converter ;
27
27
import org .springframework .data .convert .ReadingConverter ;
28
28
import org .springframework .data .convert .WritingConverter ;
29
- import org .springframework .data .elasticsearch .core .document .Document ;
30
29
import org .springframework .data .elasticsearch .core .geo .GeoJson ;
31
30
import org .springframework .data .elasticsearch .core .geo .GeoJsonGeometryCollection ;
32
31
import org .springframework .data .elasticsearch .core .geo .GeoJsonLineString ;
@@ -68,14 +67,14 @@ public class GeoConverters {
68
67
* {@link Converter} to write a {@link Point} to {@link Map} using {@code lat/long} properties.
69
68
*/
70
69
@ WritingConverter
71
- public enum PointToMapConverter implements Converter <Point , Document > {
70
+ public enum PointToMapConverter implements Converter <Point , Map < String , Object > > {
72
71
73
72
INSTANCE ;
74
73
75
74
@ Override
76
- public Document convert (Point source ) {
75
+ public Map < String , Object > convert (Point source ) {
77
76
78
- Document target = Document . create ();
77
+ Map < String , Object > target = new LinkedHashMap <> ();
79
78
target .put ("lat" , source .getY ());
80
79
target .put ("lon" , source .getX ());
81
80
return target ;
@@ -105,13 +104,13 @@ public Point convert(Map<String, Object> source) {
105
104
* {@link Converter} to write a {@link GeoPoint} to {@link Map} using {@code lat/long} properties.
106
105
*/
107
106
@ WritingConverter
108
- public enum GeoPointToMapConverter implements Converter <GeoPoint , Document > {
107
+ public enum GeoPointToMapConverter implements Converter <GeoPoint , Map < String , Object > > {
109
108
110
109
INSTANCE ;
111
110
112
111
@ 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 <> ();
115
114
target .put ("lat" , source .getLat ());
116
115
target .put ("lon" , source .getLon ());
117
116
return target ;
@@ -136,12 +135,12 @@ public GeoPoint convert(Map<String, Object> source) {
136
135
137
136
// region GeoJson
138
137
@ WritingConverter
139
- public enum GeoJsonToMapConverter implements Converter <GeoJson <? extends Iterable <?>>, Document > {
138
+ public enum GeoJsonToMapConverter implements Converter <GeoJson <? extends Iterable <?>>, Map < String , Object > > {
140
139
141
140
INSTANCE ;
142
141
143
142
@ Override
144
- public Document convert (GeoJson <? extends Iterable <?>> source ) {
143
+ public Map < String , Object > convert (GeoJson <? extends Iterable <?>> source ) {
145
144
if (source instanceof GeoJsonPoint ) {
146
145
return GeoJsonPointToMapConverter .INSTANCE .convert ((GeoJsonPoint ) source );
147
146
} else if (source instanceof GeoJsonMultiPoint ) {
@@ -196,13 +195,13 @@ public GeoJson<? extends Iterable<?>> convert(Map<String, Object> source) {
196
195
197
196
// region GeoJsonPoint
198
197
@ WritingConverter
199
- public enum GeoJsonPointToMapConverter implements Converter <GeoJsonPoint , Document > {
198
+ public enum GeoJsonPointToMapConverter implements Converter <GeoJsonPoint , Map < String , Object > > {
200
199
201
200
INSTANCE ;
202
201
203
202
@ 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 <> ();
206
205
map .put ("type" , geoJsonPoint .getType ());
207
206
map .put ("coordinates" , geoJsonPoint .getCoordinates ());
208
207
return map ;
@@ -234,13 +233,13 @@ public GeoJsonPoint convert(Map<String, Object> source) {
234
233
235
234
// region GeoJsonMultiPoint
236
235
@ WritingConverter
237
- public enum GeoJsonMultiPointToMapConverter implements Converter <GeoJsonMultiPoint , Document > {
236
+ public enum GeoJsonMultiPointToMapConverter implements Converter <GeoJsonMultiPoint , Map < String , Object > > {
238
237
239
238
INSTANCE ;
240
239
241
240
@ 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 <> ();
244
243
map .put ("type" , geoJsonMultiPoint .getType ());
245
244
map .put ("coordinates" , pointsToCoordinates (geoJsonMultiPoint .getCoordinates ()));
246
245
return map ;
@@ -269,13 +268,13 @@ public GeoJsonMultiPoint convert(Map<String, Object> source) {
269
268
270
269
// region GeoJsonLineString
271
270
@ WritingConverter
272
- public enum GeoJsonLineStringToMapConverter implements Converter <GeoJsonLineString , Document > {
271
+ public enum GeoJsonLineStringToMapConverter implements Converter <GeoJsonLineString , Map < String , Object > > {
273
272
274
273
INSTANCE ;
275
274
276
275
@ 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 <> ();
279
278
map .put ("type" , geoJsonLineString .getType ());
280
279
map .put ("coordinates" , pointsToCoordinates (geoJsonLineString .getCoordinates ()));
281
280
return map ;
@@ -304,12 +303,12 @@ public GeoJsonLineString convert(Map<String, Object> source) {
304
303
305
304
// region GeoJsonMultiLineString
306
305
@ WritingConverter
307
- public enum GeoJsonMultiLineStringToMapConverter implements Converter <GeoJsonMultiLineString , Document > {
306
+ public enum GeoJsonMultiLineStringToMapConverter implements Converter <GeoJsonMultiLineString , Map < String , Object > > {
308
307
309
308
INSTANCE ;
310
309
311
310
@ Override
312
- public Document convert (GeoJsonMultiLineString source ) {
311
+ public Map < String , Object > convert (GeoJsonMultiLineString source ) {
313
312
return geoJsonLinesStringsToMap (source .getType (), source .getCoordinates ());
314
313
}
315
314
}
@@ -332,12 +331,12 @@ public GeoJsonMultiLineString convert(Map<String, Object> source) {
332
331
333
332
// region GeoJsonPolygon
334
333
@ WritingConverter
335
- public enum GeoJsonPolygonToMapConverter implements Converter <GeoJsonPolygon , Document > {
334
+ public enum GeoJsonPolygonToMapConverter implements Converter <GeoJsonPolygon , Map < String , Object > > {
336
335
337
336
INSTANCE ;
338
337
339
338
@ Override
340
- public Document convert (GeoJsonPolygon source ) {
339
+ public Map < String , Object > convert (GeoJsonPolygon source ) {
341
340
return geoJsonLinesStringsToMap (source .getType (), source .getCoordinates ());
342
341
}
343
342
}
@@ -370,9 +369,9 @@ public enum GeoJsonMultiPolygonToMapConverter implements Converter<GeoJsonMultiP
370
369
INSTANCE ;
371
370
372
371
@ Override
373
- public Document convert (GeoJsonMultiPolygon source ) {
372
+ public Map < String , Object > convert (GeoJsonMultiPolygon source ) {
374
373
375
- Document map = Document . create ();
374
+ Map < String , Object > map = new LinkedHashMap <> ();
376
375
map .put ("type" , source .getType ());
377
376
378
377
List <Object > coordinates = source .getCoordinates ().stream () //
@@ -401,7 +400,7 @@ public GeoJsonMultiPolygon convert(Map<String, Object> source) {
401
400
Assert .isTrue (coordinates instanceof List , "coordinates must be a List" );
402
401
403
402
List <GeoJsonPolygon > geoJsonPolygons = ((List <?>) coordinates ).stream ().map (it -> {
404
- Document map = Document . create ();
403
+ Map < String , Object > map = new LinkedHashMap <> ();
405
404
map .put ("type" , GeoJsonPolygon .TYPE );
406
405
map .put ("coordinates" , it );
407
406
return map ;
@@ -415,14 +414,14 @@ public GeoJsonMultiPolygon convert(Map<String, Object> source) {
415
414
// region GeoJsonGeometryCollection
416
415
@ WritingConverter
417
416
public enum GeoJsonGeometryCollectionToMapConverter
418
- implements Converter <GeoJsonGeometryCollection , Document > {
417
+ implements Converter <GeoJsonGeometryCollection , Map < String , Object > > {
419
418
420
419
INSTANCE ;
421
420
422
421
@ Override
423
- public Document convert (GeoJsonGeometryCollection source ) {
422
+ public Map < String , Object > convert (GeoJsonGeometryCollection source ) {
424
423
425
- Document map = Document . create ();
424
+ Map < String , Object > map = new LinkedHashMap <> ();
426
425
map .put ("type" , source .getType ());
427
426
List <Map <String , Object >> geometries = source .getGeometries ().stream ()
428
427
.map (GeoJsonToMapConverter .INSTANCE ::convert ).collect (Collectors .toList ());
@@ -485,8 +484,8 @@ private static List<Point> coordinatesToPoints(List<List<Number>> pointList) {
485
484
}).collect (Collectors .toList ());
486
485
}
487
486
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 <> ();
490
489
map .put ("type" , type );
491
490
List <List <List <Double >>> coordinates = lineStrings .stream ()
492
491
.map (it -> GeoConverters .pointsToCoordinates (it .getCoordinates ())).collect (Collectors .toList ());
0 commit comments