@@ -45,11 +45,11 @@ public class ApplicationConfiguration {
|
||||
*/
|
||||
public @Bean AbstractRepositoryPopulatorFactoryBean repositoryPopulator() {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
var mapper = new ObjectMapper();
|
||||
mapper.addMixIn(GeoJsonPoint.class, GeoJsonPointMixin.class);
|
||||
mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
||||
Jackson2RepositoryPopulatorFactoryBean factoryBean = new Jackson2RepositoryPopulatorFactoryBean();
|
||||
var factoryBean = new Jackson2RepositoryPopulatorFactoryBean();
|
||||
factoryBean.setResources(new Resource[] { new ClassPathResource("starbucks-in-nyc.json") });
|
||||
factoryBean.setMapper(mapper);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package example.springdata.mongodb.geojson;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Value;
|
||||
|
||||
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
@@ -23,26 +23,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@Data
|
||||
@Document(collection = "starbucks")
|
||||
public class Store {
|
||||
public record Store(String id, String name, String street, String city, GeoJsonPoint location) {
|
||||
|
||||
String id;
|
||||
String name;
|
||||
String street;
|
||||
String city;
|
||||
|
||||
/**
|
||||
* {@code location} is stored in GeoJSON format.
|
||||
*
|
||||
* <pre>
|
||||
* <code>
|
||||
* {
|
||||
* "type" : "Point",
|
||||
* "coordinates" : [ x, y ]
|
||||
* }
|
||||
* </code>
|
||||
* </pre>
|
||||
*/
|
||||
GeoJsonPoint location;
|
||||
}
|
||||
|
||||
@@ -114,11 +114,11 @@ public class StoreRepositoryTests {
|
||||
@Test
|
||||
public void findStoresThatIntersectGivenPolygon() {
|
||||
|
||||
Document geoJsonDbo = new Document();
|
||||
var geoJsonDbo = new Document();
|
||||
|
||||
operations.getConverter().write(GEO_JSON_POLYGON, geoJsonDbo);
|
||||
|
||||
BasicQuery bq = new BasicQuery(
|
||||
var bq = new BasicQuery(
|
||||
new Document("location", new Document("$geoIntersects", new Document("$geometry", geoJsonDbo))));
|
||||
|
||||
operations.find(bq, Store.class).forEach(System.out::println);
|
||||
|
||||
Reference in New Issue
Block a user