gpt4 book ai didi

java - 使用 JAX-RS 使用 JSON

转载 作者:搜寻专家 更新时间:2023-11-01 03:08:57 25 4
gpt4 key购买 nike

我希望能够通过使用 Jackson 进行 JSON 处理的 JAX-RS 服务来使用 GeoJSON。我对如何正确处理它感到有些困惑。问题是 GeoJSON 的部分可以是数组、数组数组或数组数组的数组......我不知道如何为这种情况指定 bean。

在 GeoJSON 中,几何结构可以将坐标作为数组:

{ "type": "Point", "coordinates": [100.0, 0.0] }

或数组的数组:

{ "type": "LineString",
"coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
}

或者数组的数组:

{ "type": "Polygon",
"coordinates": [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
]
}

我如何定义要进入的 pojo?

public class Geometry {
public String type;
public List<Double> coordinates; // this
public List<List<Double>> coordinates; // or this
public List<List<List<Double>>> coordinates; // or this?

最佳答案

最终创建了一些带有 jackson 注释的 bean。我把这些放在谷歌代码中。代码可以在这里找到:http://code.google.com/p/belteshazzar-geojson/source/browse/#svn%2Ftrunk%2Fsrc%2Fmain%2Fjava%2Fcom%2Fbelteshazzar%2Fgeojson

关于java - 使用 JAX-RS 使用 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14331865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com