Ok. Thanks. Then I will use this:
// lambda use to be more explicit (could be just null)AnnotatedField
annotatedField = new AnnotatedField( ( Type t) -> { return null; }, field,
annMap);
On Wednesday, August 10, 2016 at 9:22:36 PM UTC+2, Tatu Saloranta wrote:
>
> No; it is perfectly fine to access it when an instance is passed by or
> obtained from other Jackson components. But it is not designed as something
> you should (need to) instantiate.
> But more to specific use case: PropertyNamingStrategy is not designed for
> external use: it is designed to allow one to customize the way Jackson maps
> external JSON names to/from POJO property names.
> It is being passed `AnnotatedField` and `AnnotatedMethod` since this is
> the representation Jackson uses internally, derived from class definitions.
> It is not designed as general purpose abstraction for other use.
>
> I am sure there is a way to hack TypeResolutionContext by implementing it;
> its purpose is to allow for resolution of generic types. This is necessary
> in cases where type parameter binding for a field or method is defined for
> the class: neither Field nor Method knows how type is bound, so enclosing
> class (or its sub-class) needs to be accessed to fully resolve the type.
> I think `AnnotatedClass` implements this interface.
>
> This functionality is probably not necessary for your case, nor would be
> invoked.
> So empty implementation should work fine.
>
> I hope this helps,
>
> -+ Tatu +-
>
>
> On Wed, Aug 10, 2016 at 1:09 AM, JonyD <[email protected] <javascript:>>
> wrote:
>
>> (previous messages deleted because they were not complete)
>>
>> @Tatu:
>> I am creating a PropertyNamingStrategy.
>> I need the AnnotatedField because it is a dependency of a
>> PropertyNamingStrategy.
>> So, something like this:
>>
>> private String jsonName(JsonProperty jsonProp, Field field, AnnotationMap
>> annMap ) {
>>
>> PropertyNamingStrategy strategy = getNamingStrategy(); //
>> getNamingStrategy is my personal method
>>
>>
>> if (strategy != null) {
>> MapperConfig<?> config = mapper.getSerializationConfig();
>> TypeResolutionContext typeResolutionContext = ...; // where do
>> I get this/ class that implements the TypeResolutionContext interface??
>> AnnotatedField annotatedField = new AnnotatedField(
>> typeResolutionContext, field, annMap);
>>
>>
>> return strategy.nameForField(config, annotatedField, field.getName
>> ());
>> } else {
>> return field.getName();
>> }
>> }
>>
>>
>> So you are saying that the class that has the AnnotatedField method is
>> not supposed to be accessed outside of jackson?
>> Then shouldn't that class be package protected/ protected? Or have a
>> "warning" in the javadoc saying it is an "internal" class that should be
>> only used by jackson?
>>
>> So, how can I circumvent that then?
>>
>> Thanks!
>>
>> On Wednesday, August 10, 2016 at 1:36:53 AM UTC+2, Tatu Saloranta wrote:
>>>
>>> On Tue, Aug 9, 2016 at 3:03 AM, JonyD <[email protected]> wrote:
>>>
>>>> Hi,
>>>> I will repost the question I did in stackoverflow (
>>>> http://stackoverflow.com/questions/38797189/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 method requires
>>>> now a new parameter of type TypeResolutionContext
>>>>
>>>> // v2.4.6AnnotatedField(Field field, AnnotationMap annMap)
>>>> // v2.8.1AnnotatedField(TypeResolutionContext contextClass, Field field,
>>>> AnnotationMap annMap)
>>>>
>>>> I read the API (
>>>> https://fasterxml.github.io/jackson-databind/javadoc/2.8/com/fasterxml/jackson/databind/introspect/TypeResolutionContext.html)
>>>>
>>>> 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?
>>>>
>>>
>>> This class is not intended to be instantiate by code outside of Jackson
>>> itself, so there should be no need to pass that. It is something Jackson
>>> would provide.
>>>
>>> So I think the question is rather if there is a way to do whatever you
>>> are trying to achieve without trying to construct an AnnotatedField
>>> instance.
>>>
>>> -+ Tatu +-
>>>
>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "jackson-user" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.