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