With following hierarchy,
abstract class Some<T extends Some<T>> {
}
class Other extends Some<Other> {
}
@JsonTest
abstract class SomeTest<T extends Some<T>> {
SomeTest(Class<T> entityClass) {
this.entityClass = entityClass;
}
final Class<T> entityClass;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private JacksonTester<T> jacksonTester;
}
class OtherTest extends SomeTest<Other> {
OtherTest() {
super(Other.class);
}
}
The autowired jacksonTester has the Some.class as it's resolved type which should be, I think, Other.class.
When I instantiate the jacksonTester manually, like this, it works.
@PostConstruct
private void onPostConstruct() {
jacksonTester = new JacksonTester<>(getClass(), ResolvableType.forClass(entityClass), objectMapper);
}
FYI, No jackson related annotations are in the hierarchy.
Comment From: wilkinsona
Thanks for the report. Unfortunately, I don't think there's anything we can do about this. Type erasure means that the T cannot be resolved to Other.
To use JacksonTester with a complex type hierarchy with generics, you should create it manually as you have shown above. This gives you an opportunity to provide the type information that cannot be resolved automatically.