Closed as not planned
Description
Hello, I want to report a possible regression in 6.2.0
We have some rest controllers that use jackson with @JsonTypeInfo
annotations.
With 6.1.x the attached code works and returns the expected JSON: [ { "type" : "one" }, { "type" : "two" } ]
With 6.2.0, the type properties are missing and [ {}, {} ]
is returned.
I've tracked down, that this commit may have changed the behaviour: e788aeb (#24963)
I'm unsure, if this is "works as designed" or if that code path got lost through this commit:
The method declaration public <T extends BaseType> List<T> get()
may be a bit strange, but valid java syntax.
When I use this method declaration public List<BaseType> get()
, the controller will work again. (@quaff, @jhoeller FYI)
@RestController
public class TestController {
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(value = SubType1.class, name = "one"),
@JsonSubTypes.Type(value = SubType2.class, name = "two")
})
public static class BaseType {
}
public static class SubType1 extends BaseType {
}
public static class SubType2 extends BaseType {
}
@GetMapping(value = "/test", produces = MediaType.APPLICATION_JSON_VALUE)
public <T extends BaseType> List<T> get() {
List<T> list = new ArrayList<>();
list.add((T) new SubType1());
list.add((T) new SubType2());
return list;
}
}