Relax requirement for GeoJsonMultiPoint construction allowing creation using a single point.
Only 1 point is required per GeoJson RFC and Mongo works just fine with 1 point as well. Closes #3776 Original pull request: #3777.
This commit is contained in:
committed by
Mark Paluch
parent
467536cb34
commit
36e2d80d71
@@ -28,6 +28,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* {@link GeoJsonMultiPoint} is defined as list of {@link Point}s.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Ivan Volzhev
|
||||
* @since 1.7
|
||||
* @see <a href="https://geojson.org/geojson-spec.html#multipoint">https://geojson.org/geojson-spec.html#multipoint</a>
|
||||
*/
|
||||
@@ -40,12 +41,12 @@ public class GeoJsonMultiPoint implements GeoJson<Iterable<Point>> {
|
||||
/**
|
||||
* Creates a new {@link GeoJsonMultiPoint} for the given {@link Point}s.
|
||||
*
|
||||
* @param points points must not be {@literal null} and have at least 2 entries.
|
||||
* @param points points must not be {@literal null} and have at least 1 entry.
|
||||
*/
|
||||
public GeoJsonMultiPoint(List<Point> points) {
|
||||
|
||||
Assert.notNull(points, "Points must not be null.");
|
||||
Assert.isTrue(points.size() >= 2, "Minimum of 2 Points required.");
|
||||
Assert.isTrue(points.size() >= 1, "Minimum of 1 Point required.");
|
||||
|
||||
this.points = new ArrayList<Point>(points);
|
||||
}
|
||||
@@ -69,6 +70,19 @@ public class GeoJsonMultiPoint implements GeoJson<Iterable<Point>> {
|
||||
this.points.addAll(Arrays.asList(others));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link GeoJsonMultiPoint} for the given {@link Point}.
|
||||
*
|
||||
* @param point must not be {@literal null}.
|
||||
*/
|
||||
public GeoJsonMultiPoint(Point point) {
|
||||
|
||||
Assert.notNull(point, "First point must not be null!");
|
||||
|
||||
this.points = new ArrayList<Point>();
|
||||
this.points.add(point);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.geo.GeoJson#getType()
|
||||
|
||||
@@ -63,6 +63,7 @@ import com.mongodb.client.MongoCollection;
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @author Ivan Volzhev
|
||||
*/
|
||||
@ExtendWith({ MongoClientExtension.class, SpringExtension.class })
|
||||
@ContextConfiguration
|
||||
@@ -329,6 +330,21 @@ public class GeoJsonTests {
|
||||
assertThat(result.geoJsonMultiPoint).isEqualTo(obj.geoJsonMultiPoint);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-3776
|
||||
public void shouldSaveAndRetrieveDocumentWithGeoJsonMultiPointTypeWithOnePointCorrectly() {
|
||||
|
||||
DocumentWithPropertyUsingGeoJsonType obj = new DocumentWithPropertyUsingGeoJsonType();
|
||||
obj.id = "geoJsonMultiPoint";
|
||||
obj.geoJsonMultiPoint = new GeoJsonMultiPoint(new Point(0, 0));
|
||||
|
||||
template.save(obj);
|
||||
|
||||
DocumentWithPropertyUsingGeoJsonType result = template.findOne(query(where("id").is(obj.id)),
|
||||
DocumentWithPropertyUsingGeoJsonType.class);
|
||||
|
||||
assertThat(result.geoJsonMultiPoint).isEqualTo(obj.geoJsonMultiPoint);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1137
|
||||
public void shouldSaveAndRetrieveDocumentWithGeoJsonMultiPolygonTypeCorrectly() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user