【发布时间】:2017-03-13 04:15:43
【问题描述】:
我以前从未使用过 Spring Boot,我想使用 mongodb 创建一个小型 REST 服务。我在数据库中存储了一些空间数据,并希望通过其余接口访问它们。这很有效,而且非常简单,但我正在努力使用默认的 mappig/marshalling 获得的 Geojson 表示。
这就是我目前所拥有的:
POJO:
@Document(collection = "geofences")
public class Geofence {
@Id
private String id;
private String topic;
private Date expiresOn;
private GeoJsonPolygon geo;
// getters and setters
}
mongodb 中的文档:
{ "_id" : ObjectId("5816b03b71e2e892bd7846f3"), "topic" : "ok", "expiresOn" : ISODate("2017-01-01T00:00:00Z"), "geo" : { "type" : "Polygon", "coordinates" : [ [ [ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 ] ] ] } }
REST 控制器中的方法:
public ResponseEntity<Collection<Geofence>> getAll() {
return new ResponseEntity<>(repository.findAll(), HttpStatus.OK);
}
通过调用其余服务,我希望收到 geojson 部分,就像它在我的文档中一样,但我得到了这个:
[
{
"id": "5816b03b71e2e892bd7846f3",
"topic": "ok",
"expiresOn": 1483228800000,
"geo": {
"points": [
{
"x": 0,
"y": 0,
"type": "Point",
"coordinates": [
0,
0
]
},
{
"x": 3,
"y": 6,
"type": "Point",
"coordinates": [
3,
6
]
},
{
"x": 6,
"y": 1,
"type": "Point",
"coordinates": [
6,
1
]
},
{
"x": 0,
"y": 0,
"type": "Point",
"coordinates": [
0,
0
]
}
],
"coordinates": [
{
"type": "LineString",
"coordinates": [
{
"x": 0,
"y": 0,
"type": "Point",
"coordinates": [
0,
0
]
},
{
"x": 3,
"y": 6,
"type": "Point",
"coordinates": [
3,
6
]
},
{
"x": 6,
"y": 1,
"type": "Point",
"coordinates": [
6,
1
]
},
{
"x": 0,
"y": 0,
"type": "Point",
"coordinates": [
0,
0
]
}
]
}
],
"type": "Polygon"
}
}
]
有什么建议吗?我该如何改变这种行为?
【问题讨论】:
标签: java mongodb rest spring-boot geojson