- when using WriteClassName feature, it outputs a strange classname.
- parse json without classname, I get empty content.
Ask for help. Please check what happed.
public class MultimapTest {
public static void main(String[] args) {
System.setProperty("fastjson.parser.autoTypeSupport","true");
Multimap<String, List> mt = ArrayListMultimap.create();
mt.put("multimap1", Arrays.asList("1","2","3"));
System.out.println("json string with class name: ");
String jsonWithClass = JSON.toJSONString(mt, SerializerFeature.WriteClassName);
System.out.println(jsonWithClass);
try {
System.out.println(JSON.parse(jsonWithClass));
} catch (Throwable e) {
//com.alibaba.fastjson.JSONException: unsupport type class com.google.common.collect.AbstractMapBasedMultimap$AsMap
e.printStackTrace();
}
Multimap<String, List> stringListMultimap = JSON.parseObject(JSON.toJSONString(mt), new TypeReference<ArrayListMultimap<String, List>>() {
});
System.out.println(stringListMultimap);
}
}
1条答案
按热度按时间tcomlyy61#
@wenshao