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
FieldTypeResolver
wenshao edited this page Apr 13, 2016
·
9 revisions
FieldTypeResolver是1.2.9 & 1.1.49.android中引入的新功能,用于解析嵌套对象时,自动识别子对象的类型信息。FieldTypeResolver只会作用于value类型为json object的字段。
例如:
public static class Item {
public int value;
}
FieldTypeResolver fieldResolver = new FieldTypeResolver() {
public Type resolve(Object object, String fieldName) {
if (fieldName.startsWith("item_")) {
return Item.class;
}
return null;
}
};
String text = "{\"item_0\":{\"value\":1001},\"item_1\":{\"value\":1002}}";
JSONObject jsonObject = JSON.parseObject(text, JSONObject.class, fieldResolver);
Assert.assertTrue(jsonObject.get("item_0") instanceof Item);
Assert.assertTrue(jsonObject.get("item_1") instanceof Item);
如有需要修改本注脚,请联系阿里巴巴,
© 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