tags:

views:

204

answers:

1

I have this question:

How to populate this object from a struts2 action. My action populates without any problem a lot of my objects, but I have a restriction on a JSON input. My input is like this:

I don't now how to populate...The class geometry can have a double[] or double[][] or double[][][] because the JSON input can have multiple geometry types. Json examples:

{ "geometry" : { "coordinates" : [331450.0638554565,5128924.597221361],
            "type" : "Point"
          } 

{ "geometry" : { "coordinates" : [  
              [ 331889.57676804002,5130491.5563009996],
                      [ 330991.44168580999,5129555.2027046001],
                      [ 331450.0638554565,5128924.597221361]
                      ],
                "type" : "Linestring"
              }

{ "geometry" : { "coordinates" : [ [ 
              [ 331889.57676804002,5130491.5563009996],
                      [ 330991.44168580999,5129555.2027046001],
                      [ 331450.0638554565,5128924.597221361],
                      [ 332749.49333611998,5128332.2102522003],
                      [ 333953.37653145002,5129153.9083062001],
                      [ 333972.48578852002,5129822.7323035998],
                      [ 332615.72853664,5129880.0600747997],
                      [ 331889.57676804002,5130491.5563009996] ] ],
                "type" : "Polygon"
              }

And my object is this:

public class Geometry {


    private String type;
    private Object coordinates;

    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public Object getCoordinates() {
        return coordinates;
    }
    public void setCoordinates(Object coordinates) {
        this.coordinates = coordinates;
    }
}

If I modify my geometry class to double[] coordinates...it works, but only with point geometry...

I use struts2 2.1.8 with json plugin.

Many thanks

A: 

You should try defining "coordinates" as a List.

John Lindal