JonyD JonyD - 2 months ago 5x
JSON Question

How to access TypeResolutionContext in jackson 2.8.1

I am upgrading jackson library in a java project from version 2.4.6 to the latest version (2.8.1).
The following AnnotatedField constructor requires now a new parameter of type TypeResolutionContext

// v2.4.6
AnnotatedField(Field field, AnnotationMap annMap)

// v2.8.1
AnnotatedField(TypeResolutionContext contextClass, Field field, AnnotationMap annMap)

I read the API ( but can't find how to get this TypeResolutionContext.

Only 2 classes implement this TypeResolutionContext (AnnotatedClass and TypeResolutionContext.Basic) but none of them seem to have suitable accessor methods that return a TypeResolutionContext.

Anyone knows how can I get it?


The AnnotatedField constructor, although public, should not be used directly -- it was not designed to be instantiated. So, the TypeResolutionContext parameter will in most cases work just fine if it is empty implemented, like this:

// lambda use to be more explicit (could be just null)
AnnotatedField annotatedField = new AnnotatedField( ( Type t) -> { return null; }, field, annMap);

(+ info a bit out of topic: PropertyNamingStrategy is also not supposed to be used outside of jackson project.)