Postgresql有一个geom_id,它基本上是由地图上某个点的纬度和经度生成的id。如何使用该ID使用GSON创建JSON对象?
这是我的解析器。
package database;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import database.GeoJSONParser.Layer.Layer_Geometry;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
public class GeoJSONParser {
public class Layer {
public class Layer_Geometry {
private String type;
private String coordinates;
@Override
public String toString() {
return type + " - " + coordinates;
}
}
public class Geom_return {
private Layer_Geometry Geom ;
@Override
public String toString() {
return (" + Geom + ");
}
}
public class JSONtoJava {
public void main(String[] args) throws IOException {
Reader reader = new InputStreamReader(GeoJSONParser.class.getResourceAsStream("Server1.json"));
Gson gson = new GsonBuilder().create();
Geom_return Geom1 = gson.fromJson(reader, Geom_return.class);
System.out.println(Geom1);
reader.close();
}
}
}
}
这是JSON:
{"type":"Feature", "id":"OpenLayers.Feature.Vector_108",
"properties":{}, "geometry":{"type":"Point", "coordinates":[13.148438036442, 7.6347658038139]},
"crs":{"type":"OGC", "properties":{"urn":"urn:ogc:def:crs:OGC:1.3:CRS84"}}}
如何使用将从postgresql表返回的geom对象构建JSON构建器?