2010-04-07 103 views
0

我有这个问题:JSON与struts2,如何填充此对象?

如何从struts2操作填充此对象? 我的动作填充没有任何问题我的很多对象,但我有一个JSON输入的限制。我的输入是这样的:

我现在不怎么填充。类几何可以具有double[]double[][]double[][][],因为JSON输入可以具有多种几何类型。 Json的例子:

{ "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" 
       } 

而我的目标是:

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; 
    } 
} 

如果我修改我的几何课以double[]坐标,它的工作原理,但只有点几何。

我使用struts2 2.1.8和json插件。

非常感谢。

回答

-1

您应该尝试将“坐标”定义为列表。