This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
BuilderSupport
wenshao edited this page Feb 28, 2016
·
1 revision
这个功能参考自jackson。 POJO的Builder通过@JSONType来配置,如下:
VO vo = JSON.parseObject("{\"id\":12304,\"name\":\"ljw\"}", VO.class);
Assert.assertEquals(12304, vo.getId());
Assert.assertEquals("ljw", vo.getName());
@JSONType(builder=VOBuilder.class)
public static class VO {
private int id;
private String name;
public int getId() {
return id;
}
public String getName() {
return name;
}
}
// 如果builder方法是build或者create,能自动识别
@JSONPOJOBuilder(buildMethod="xxx")
public static class VOBuilder {
private VO vo = new VO();
public VO xxx() {
return vo;
}
public VOBuilder withId(int id) {
vo.id = id;
return this;
}
public VOBuilder withName(String name) {
vo.name = name;
return this;
}
}
如有需要修改本注脚,请联系阿里巴巴,
© Alibaba Fastjson Develop Team
注明: 版权所有阿里巴巴,请注明版权所有者
If you need to amend this footnote, please contact Alibaba.
© Alibaba Fastjson Develop Team
Note: Copyright Alibaba, please indicate the copyright owner