<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 156,  comments - 601,  trackbacks - 0
    svenson是一個用于生成和解析JSON數(shù)據(jù)格式的Java5開源類庫。它能夠?qū)SON數(shù)據(jù)集轉(zhuǎn)換成Java對象或相反的操作。

    下面是一些示例:

    Svenson offers you the possibility to generate JSON datasets from your java classes being a nested graph of:

    • POJOs
    • Java Beans
    • Arrays
    • Collections
    • Maps

    In the most simple case you can just do a

    import org.svenson.JSON;



    ...







    String json = JSON.defaultJSON().forValue( yourObjects );

    you can also generate JSON while ignoring certain properties:

    import org.svenson.JSON;



    ...







    String json = JSON.defaultJSON().forValue( yourObjects, Arrays.asList("foo","bar"));

    This would generate JSON for "yourObjects" while ignoring all properties named "foo" and "bar" in all beans.

    @JSONProperty

    The org.svenson.JSONProperty annotation allows you to define another JSON property name for your properties, make JSON ignore your properties completely or ignore them if they are null.

    import org.svenson.JSON;



    import org.svenson.JSONProperty;







    public class MyBean



    {



       
    private String foo,bar,baz;

       
    @JSONProperty("notFoo")
       
    public String getFoo()
       
    {
         
    return foo;
       
    }

       
    @JSONProperty(ignoreIfNull = true)
       
    public String getBar()
       
    {
           
    return foo;
       
    }

       
    @JSONProperty(ignore = true)
       
    public String getBaz()
       
    {
           
    return foo;
       
    }

    }

    Here the foo property would be generated as "notFoo" property in JSON, the "bar" property would be ignored if it is null, and the "baz" property would be ignored completely.

    JSONable

    If your classes implement the org.svenson.JSONable, they can provide their own JSON representation.

    import org.svenson.JSON;



    import org.svenson.JSONable;







    public class MyClass implements JSONable



    {



       
    private String member;



       
    ...



       
    public String toJSON()



       
    {



             
    return JSON.defaultJSON().quote(this.member);



       
    }



    }

    Here MyClass would just generate one of its members as JSON string. As you can see, you can use the JSON class to help you implementing toJSON().

    JSONifier

    A JSONifier is a class that can convert another class into JSON. It needs to implement org.svenson.JSONifier.

    import org.svenson.JSON;



    import org.svenson.JSONifier;







    public class MyJSONifier implements JSONifier



    {



       
    public String toJSON(Object o)



       
    {



             
    MyClass myClass = (MyClass)o;



             
    return JSON.defaultJSON().quote(myClass.getMember());



       
    }



    }

    This would be a simple JSONifier that turns instances of MyClass into JSON by replacing them with one of its members. To use this JSONifier you have to register it in your own JSON instance.

    import org.svenson.JSON;



       
    ...



       
    // assume myClassInstance is an instance of MyClass



        JSON json
    = new JSON();



        json
    .registerJSONifier(MyClass.class, new MyJSONifier());







       
    String output = json.forValue( myClassInstance);

    svenson 官方網(wǎng)址:http://code.google.com/p/svenson/

    Good Luck!
    Yours Matthew!
    posted on 2008-12-29 21:35 x.matthew 閱讀(3129) 評論(0)  編輯  收藏 所屬分類: 最新開源動態(tài)Best Practise(JDK API)
    主站蜘蛛池模板: 亚洲国产美女精品久久| 免费国产黄网站在线观看动图 | 黄色免费在线网站| 亚洲欧洲日产韩国在线| 免费黄网在线观看| 免费国产污网站在线观看| 亚洲不卡1卡2卡三卡2021麻豆| 国产精品成人无码免费| 免费无码黄网站在线看| 亚洲AV成人一区二区三区在线看| 亚洲精品tv久久久久| 37pao成人国产永久免费视频| 亚洲AV无码精品国产成人| 亚洲男人的天堂在线播放| 成人国产mv免费视频| 日韩免费的视频在线观看香蕉| 在线亚洲午夜片AV大片| 亚洲色自偷自拍另类小说| 国产精品成人免费视频网站京东| 精品免费久久久久国产一区 | 久久久久久久国产免费看 | 亚洲最大无码中文字幕| 国产成人A亚洲精V品无码 | 免费国产高清视频| 亚洲一级毛片免费观看| 成人国产网站v片免费观看| 亚洲乱人伦精品图片| 亚洲人成网站在线观看播放| 国内大片在线免费看| 99久久久国产精品免费蜜臀| 一级毛片免费不卡| 久久亚洲精品无码网站| 亚洲成人高清在线观看| 国产成人精品日本亚洲| 亚洲欧洲日产国码一级毛片| 日韩免费观看视频| 桃子视频在线观看高清免费完整| 大地影院MV在线观看视频免费 | 美女视频黄的免费视频网页| 老司机午夜免费视频| 亚洲日韩精品无码专区加勒比|