-
Jan 16th, 2013, 01:21 PM
#1
Parse GML string to application/GML+XML mediaType using *.http.MediaType
Hi,
I am working on a spring+ hibernate + postgres application, In one of the tables I have a column called geom with the Geometry. So I have annotated that entity column with @JsonSerialize(using = JsonGeometrySerializer.class) So my geometrySerializer takes that geometry and creates a wkt string of the geometry and addes it to the json object output. Below that in the json I want to add the GML of the same geometry. I do that again by GMLWriter.write(geom) which will return a gml string in the JSON. But what I want to do is in the place of GML string I want to add the GML mediaType which is not a string, so that when the json is viewed in the browser the GML tags can be expanded/collapsed. I think this can be achieved by using org.springframework.http.MediaType and serialize the geometry? Is this correct. Can any one provide an example please?
@Entity
...
...
@JsonSerialize(using = JsonGeometrySerializer.class)
public Geometry getGeom() {
return geom;
}
...
public class JsonGeometrySerializer extends JsonSerializer<Geometry> {
@Override
public void serialize(Geometry geom, JsonGenerator gen,
SerializerProvider provider) throws IOException,
JsonProcessingException {
...
...
GeometryFactory gf = new GeometryFactory();
if (geom != null) {
geom = geom.getEnvelope();
String wkt = wWriter.write(geom);
String gml = gWriter.write(geom);
gen.writeStartObject();
gen.writeStringField("wkt", wkt);
gen.writeFieldName("gml");
gen.writeStartArray();
gen.writeObject(gml);
gen.writeEndArray();
gen.writeEndObject();
}
Or is there a way GML can be embedded inside JSON without making GML a string?
Last edited by Ben_java; Jan 18th, 2013 at 08:34 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules