-
Notifications
You must be signed in to change notification settings - Fork 6.5k
WriteAs_CN
温绍锦 edited this page Apr 11, 2019
·
1 revision
在某些场景中,序列化希望按父类的字段信息,不包括子类的字段。在1.2.57中提供了支持。比如:
public class Issue2289 extends TestCase {
public void test_for_issue() throws Exception {
B b = new B();
b.id = 123;
JSONSerializer jsonSerializer = new JSONSerializer();
jsonSerializer.writeAs(b, A.class); // 按父类序列化
String str = jsonSerializer.toString();
assertEquals("{}", str);
}
public static class A {
}
public static class B extends A {
public int id;
}
}
如有需要修改本注脚,请联系阿里巴巴,
© 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