Genson :一个快速、可扩展的JSON数据转换Java类库

openkk 12年前

Genson是一个开源的Java类库,用于实现Java到Json和 Json到Java的转换。Genson具备可扩展,并且还可配置,快速和易于使用。
示例代码:

class Person {   String fullName;   // will be converted even if it is private   @JsonProperty private Date birthDate;   Adress adress;   @JsonIgnore public int ignoredField;   private int privateNotDetected;   private Person() {}     @Creator public static Person create() {     return new Person();   }     public String getFullName(){    // will be used instead of direct field access   }  }    class Adress {    final int building;    final String street;    // only a constructor with arguments genson will use it during deserialization    public Adress(@JsonProperty("building") int building, @JsonProperty("street")  String street) {    }  }    Person someone = new Person("eugen", new GregorianCalendar(1986, 1, 16).getTime(), new Adress(157, "paris"));  // we obtain the following json string  //{"adress":{"building":157,"street":"paris"},"birthDate":"16 févr. 1986","happy":true,"fullName":"eugen"}  String json = genson.serialize(someone);     // now we deserialize it back  someone = genson.deserialize(json, Person.class);

项目主页:http://www.open-open.com/lib/view/home/1344926865991