Announcement Announcement Module
No announcement yet.
Parse GML string to application/GML+XML mediaType using *.http.MediaType Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Parse GML string to application/GML+XML mediaType using *.http.MediaType


    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?

    @JsonSerialize(using = JsonGeometrySerializer.class)
    public Geometry getGeom() {
    return geom;

    public class JsonGeometrySerializer extends JsonSerializer<Geometry> {

    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.writeStringField("wkt", wkt);



    Or is there a way GML can be embedded inside JSON without making GML a string?
    Last edited by Ben_java; Jan 18th, 2013, 08:34 AM.