Genson :一個快速、可擴展的JSON數據轉換Java類庫

openkk 12年前發布 | 57K 次閱讀 JSON JSON開發包

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);</pre>

項目主頁:http://www.baiduhome.net/lib/view/home/1344926865991

 本文由用戶 openkk 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!