public class Person implements JSONString {
private String name;
private String lastname;
private Address address;
// getters & setters
public String toJSONString() {
return "{name:‘"+name+"‘,lastname:‘"+lastname+"‘}";
}
}
2.第二种方法通过jsonconfig实例,对包含和需要排除的属性进行方便的添加或删除
public class Person {
private String name;
private String lastname;
private Address address;
// getters & setters
}
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExclusions( new String[]{"address"});
Person bean = new Person("jack","li");
JSON json = JSONSerializer.toJSON(bean, jsonConfig);