当前位置:编程学习 > JAVA >>

jackson处理json,类中的某个属性是个父类,根据json字符串可变时,怎么转换

java类
public class Feature {

public Geometry getGeometry() {
return geometry;
}

public void setGeometry(Geometry geometry) {
this.geometry = geometry;
}

public Hashtable<String, Object> getAttributes() {
return attributes;
}

public void setAttributes(Hashtable<String, Object> attributes) {
this.attributes = attributes;
}

private Geometry geometry;
private Hashtable<String, Object> attributes;
}

其中的Geometry是个父类,没有属性,子类包括Point(double x,y),MultiPoint(ArrayList<ArrayList<Double>>),Path/Ring(ArrayList<ArrayList<ArrayList<Double>>>)等。
括号里的是属性,get和set就省略了。

json字符串例子为:

  {
    "geometry" : {"x" : -118.15, "y" : 33.80},  
    "attributes" : {
      "OWNER" : "Joe Smith",
      "VALUE" : 94820.37,
      "APPROVED" : true,
      "LASTUPDATE" : 1227663551096
    }
  }

或者

{
    "geometry" : 
    {
      "paths" : 
      [
        [
          [-95.9899452281111, 38.1345878074741], 
          [-95.9898896947778, 38.1344644074744], 
          [-95.9899164947778, 38.1343866074744]
        ]
      ]
    },"attributes" : {
      "objectid" : 1, 
      "fdate" : 932428800000, 
      ...
    }
  }

问题是怎么用jackson转换json字符串为Feature,并保证json的信息都存储进去。普通的ObjectMapper.readValue(String,Class)是不行了吧,用JsonParser又太麻烦,我感觉答案应该就在filter和注解上,但不熟悉,求大神指点。 json jackson filter --------------------编程问答-------------------- 父类没有属性的话,可以声明父类的对象并赋予值么?
Son son=new Father();可以
但是
Father father=new Son();可以么?
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,