是否考虑支持Immutable的反序列化?
public class FastJsonGuavaTest {
@Test
public void immutableMapTest() {
Object obj = ImmutableMap.of("abc", "abc", "123", "123");
Class<?> clazz = obj.getClass();
String jsonData = JSON.toJSONString(obj);
System.out.println(jsonData);
//此处抛出异常:om.alibaba.fastjson.JSONException: unsupport type class com.google.common.collect.RegularImmutableMap
obj = JSON.parseObject(jsonData, clazz);
System.out.println(JSON.toJSONString(obj));
}
@Test
public void immutableMapTest2() {
ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
Object obj = ImmutableMap.of("abc", "abc", "123", "123");
Class<?> clazz = obj.getClass();
String jsonData = JSON.toJSONString(obj,
SerializerFeature.WriteClassName);
System.out.println(jsonData);
//抛出异常:om.alibaba.fastjson.JSONException: unsupport type class com.google.common.collect.RegularImmutableMap
obj = JSON.parseObject(jsonData, clazz);
System.out.println(JSON.toJSONString(obj));
}
}
1条答案
按热度按时间0ejtzxu11#
+1