我有以下代码
@org.junit.Test
public void test1() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
Map<UUID, String> map = new HashMap<UUID, String>();
map.put(new UUID(1,2), "value1");
Set<Map<UUID, String>> set = new LinkedHashSet<Map<UUID,String>>();
set.add(map);
System.out.println(objectMapper.writeValueAsString(set));
}
产生输出
["java.util.LinkedHashSet",[{"@class":"java.util.HashMap","00000000-0000-0001-0000-000000000002":"value1"}]]
我正在尝试让Jackson打印UUID的完全限定的java类以及我在Map中的String对象。