文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>JavaBean <--> JSON

JavaBean <--> JSON

时间:2010-06-22  来源:btpka3

Lib:
commons-beanutils-1.8.2.jar
commons-codec-1.4.jar
commons-collections-3.2.1.jar
commons-io-1.4.jar
commons-lang-2.5.jar
commons-logging-1.1.1.jar
ezmorph-1.0.6.jar
json-lib-2.3-jdk15.jar


文件: test.zip
大小: 6KB
下载: 下载


Person.java

package test.json;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class Person {

    private static final long serialVersionUID = 1L;

    private String name;

    private Integer age;

    private boolean male;

    private Date birthday;

    private String[] alias;

    private byte[] imageData;

    private List<String> favors;

    private Map<String, String> addrs;

    private Object nullObject = null;

    private Person parent;

    private Person child;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public boolean isMale() {
        return male;
    }

    public void setMale(boolean male) {
        this.male = male;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String[] getAlias() {
        return alias;
    }

    public void setAlias(String[] alias) {
        this.alias = alias;
    }

    public byte[] getImageData() {
        return imageData;
    }

    public void setImageData(byte[] imageData) {
        this.imageData = imageData;
    }

    public List<String> getFavors() {
        return favors;
    }

    public void setFavors(List<String> favors) {
        this.favors = favors;
    }

    public Map<String, String> getAddrs() {
        return addrs;
    }

    public void setAddrs(Map<String, String> addrs) {
        this.addrs = addrs;
    }

    public Person getParent() {
        return parent;
    }

    public void setParent(Person parent) {
        this.parent = parent;
    }

    public Person getChild() {
        return child;
    }

    public void setChild(Person child) {
        this.child = child;
    }

    public Object getNullObject() {
        return nullObject;
    }

    public void setNullObject(Object nullObject) {
        this.nullObject = null;
    }
}



Output:


----------JsonUtilTest#testGetInstance01()-----

{
  "addrs": {
    "SD": "ShanDong",
    "HN": "HeNan"
  },
  "age": 25,
  "alias": [
    "S_A_0",
    "S_A_1",
    "S_A_2"
  ],
  "birthday": "1985-05-05 05:05:05,005",
  "child": null,
  "favors": [
    "S_F_0",
    "S_F_1",
    "S_F_2",
    " test \n\t<>,\"\"_'ABC'&&|| "
  ],
  "imageData": "AQIDBA==\r\n",
  "male": true,
  "name": "son",
  "nullObject": null,
  "parent": {
    "addrs": {
      "TJ": "TianJin",
      "BJ": "BeiJing"
    },
    "age": 50,
    "alias": [
      "M_A_0",
      "M_A_1",
      "M_A_2"
    ],
    "birthday": "1960-06-06 06:06:06,006",
    "child": null,
    "favors": [
      "M_F_0",
      "M_F_1",
      "M_F_2"
    ],
    "imageData": "ChQeKA==\r\n",
    "male": false,
    "name": "mom",
    "nullObject": null,
    "parent": null
  }
}

----------JsonUtilTest#testGetInstance02()---------------

{
  "addrs": null,
  "age": null,
  "alias": null,
  "birthday": null,
  "child": null,
  "favors": null,
  "imageData": null,
  "male": false,
  "name": null,
  "nullObject": null,
  "parent": null
}


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载