我发现杰克逊 JSON 处理器库的一些奇怪行为,我很好奇这是故意的还是错误的。请看下面的代码:
@JsonTypeInfo(use = Id.NAME)
public class Nut {}
…</p>
ObjectMapper mapper = new ObjectMapper();
Nut nut = new Nut();
Object object = new Nut();
Nut[] nuts = new Nut[] { new Nut() };
Object[] objects = new Object[] { new Nut() };
System.out.println(mapper.writeValueAsString(nut));
System.out.println(mapper.writeValueAsString(object));
System.out.println(mapper.writeValueAsString(nuts));
System.out.println(mapper.writeValueAsString(objects));
输出:
{"@type":"Nut"}
{"@type":"Nut"}
[{"@type":"Nut"}]
[{}]
我期望(和想要)的是以下内容:
{"@type":"Nut"}
{"@type":"Nut"}
[{"@type":"Nut"}]
[{"@type":"Nut"}] // <<< type information included
我错过了什么还是应该提交错误报告?