I found the strange behavior of the Jackson JSON processor library and I wonder if this is intentional or an error. Take a look at the code below:
@JsonTypeInfo(use = Id.NAME) public class Nut {}
...
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));
Conclusion:
{"@type":"Nut"} {"@type":"Nut"} [{"@type":"Nut"}] [{}]
What I expect (and want) is the following:
{"@type":"Nut"} {"@type":"Nut"} [{"@type":"Nut"}] [{"@type":"Nut"}] // <<< type information included
Am I missing something or should I post a bug report?
source share