升级fastjson到1.2.55版本
This commit is contained in:
parent
6f01de07e9
commit
88e82ac855
2
pom.xml
2
pom.xml
@ -45,7 +45,7 @@
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.1.42</version>
|
||||
<version>1.2.55</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
|
||||
@ -138,58 +138,4 @@ public class ExtJsonUtils {
|
||||
public interface ExtExtractor {
|
||||
String getExt(Object bean);
|
||||
}
|
||||
|
||||
private static class MetaInfo {
|
||||
private final static ParserConfig INSTANCE = ParserConfig.getGlobalInstance();
|
||||
|
||||
private final Object object;
|
||||
private final Map<String, FieldDeserializer> map;
|
||||
private final JSONObject ext = new JSONObject();
|
||||
|
||||
private MetaInfo(Object object) {
|
||||
this.object = object;
|
||||
this.map = INSTANCE.getFieldDeserializers(object.getClass());
|
||||
}
|
||||
|
||||
void gather(String key, Object value) {
|
||||
if (!map.containsKey(key)) {
|
||||
ext.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(ExtExtractor extractor) {
|
||||
JSONObject old = JSON.parseObject(extractor.getExt(object));
|
||||
if (old == null) {
|
||||
old = new JSONObject();
|
||||
}
|
||||
old.putAll(ext);
|
||||
map.get(EXT_NAME).setValue(object, old.toJSONString());
|
||||
}
|
||||
|
||||
static boolean hasExt(Class<?> clazz) {
|
||||
return INSTANCE.getFieldDeserializers(clazz).containsKey(EXT_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T parseObject(String text, final Class<T> clazz, ExtExtractor extractor) {
|
||||
final Map<Object, MetaInfo> map = new HashMap<>();
|
||||
|
||||
T object = JSON.parseObject(text, clazz, new ExtraProcessor() {
|
||||
@Override
|
||||
public void processExtra(Object object, String key, Object value) {
|
||||
if (!map.containsKey(object) && MetaInfo.hasExt(object.getClass())) {
|
||||
map.put(object, new MetaInfo(object));
|
||||
}
|
||||
if (map.containsKey(object)) {
|
||||
map.get(object).gather(key, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (Map.Entry<Object, MetaInfo> entry : map.entrySet()) {
|
||||
entry.getValue().update(extractor);
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user