Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Jul 29, 2026. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 6.4k
JSONType_typeKey_cn
高铁 edited this page May 30, 2017
·
1 revision
在某些场景,需要使用非缺省typeKey,在1.1.58.android支持@JSONType.typeKey配置。
@JSONType(seeAlso = {FloorV2.class}, typeKey = "type")
publicinterfaceArea {
publicstaticfinalStringTYPE_SECTION = "section";
publicstaticfinalStringTYPE_FLOORV1 = "floorV1";
publicstaticfinalStringTYPE_FLOORV2 = "floorV2";
}
@JSONType(typeName = "floorV2")
publicstaticclassFloorV2implementsArea {
publicStringtype;
publicStringtemplateId;
}
// testcase codeStringjson = "{\"type\":\"floorV2\",\"templateId\":\"x123\"}";
FloorV2floorV2 = (FloorV2) JSON.parseObject(json, Area.class);
assertNotNull(floorV2);
assertNotNull(floorV2.templateId);
assertEquals("x123", floorV2.templateId);
assertEquals("floorV2", floorV2.type);
Stringjson2 = JSON.toJSONString(floorV2, SerializerFeature.WriteClassName);
assertEquals("{\"type\":\"floorV2\",\"templateId\":\"x123\"}", json2);如有需要修改本注脚,请联系阿里巴巴,
© 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