Skip to content

Commit 40c3204

Browse files
thiagodstichristophstrobl
authored andcommitted
DATAMONGO-1607 - Fix ClassCastException in Circle, Point and Sphere when coordinates are not Double.
Original Pull Request: #438
1 parent 6ad5f62 commit 40c3204

File tree

1 file changed

+10
-3
lines changed
  • spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert

1 file changed

+10
-3
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/GeoConverters.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
* @author Thomas Darimont
5454
* @author Oliver Gierke
5555
* @author Christoph Strobl
56+
* @author Thiago Diniz da Silveira
5657
* @since 1.5
5758
*/
5859
abstract class GeoConverters {
@@ -120,8 +121,11 @@ public Point convert(DBObject source) {
120121
if (source.containsField("type")) {
121122
return DbObjectToGeoJsonPointConverter.INSTANCE.convert(source);
122123
}
124+
125+
Number x = (Number) source.get("x");
126+
Number y = (Number) source.get("y");
123127

124-
return new Point((Double) source.get("x"), (Double) source.get("y"));
128+
return new Point(x.doubleValue(), y.doubleValue());
125129
}
126130
}
127131

@@ -255,7 +259,8 @@ public Circle convert(DBObject source) {
255259
}
256260

257261
DBObject center = (DBObject) source.get("center");
258-
Double radius = (Double) source.get("radius");
262+
Number radiusNumber = (Number) source.get("radius");
263+
Double radius = radiusNumber.doubleValue();
259264

260265
Distance distance = new Distance(radius);
261266

@@ -326,7 +331,9 @@ public Sphere convert(DBObject source) {
326331
}
327332

328333
DBObject center = (DBObject) source.get("center");
329-
Double radius = (Double) source.get("radius");
334+
Number radiusNumber = (Number) source.get("radius");
335+
Double radius = radiusNumber.doubleValue();
336+
330337

331338
Distance distance = new Distance(radius);
332339

0 commit comments

Comments
 (0)