Re: [jackson-user] Deprecated findSerializationType might be breaking refineSerializationType (v2.8.1)

2016-08-11 Thread Tatu Saloranta
Your suggestion sounds plausible, but to fix it, as well as to guard
against regression, it would be necessary to have a way to reproduce the
problem.
So if there is any way you could suggest a way to trigger the problem that
would be great.

Exception, however, would seem to indicate some other kind of problem...
either way it would be good to figure out what is going wrong.

-+ Tatu +-



On Thu, Aug 11, 2016 at 8:33 AM, JonyD  wrote:

> In https://github.com/FasterXML/jackson-databind/
> blob/master/src/main/java/com/fasterxml/jackson/databind/
> AnnotationIntrospector.java
> the method findSerializationType is deprecated since v2.7 and returns
> always null.
> The method refineSerializationType (which is the new method that should be
> used instead of findSerializationType) uses/calls the findSerializationType
> in some parts with logic [if(... ].
> I think this makes refineSerializationType broken.
>
> I get the following exception in a custom Serialization:
> com.fasterxml.jackson.databind.JsonMappingException: Can not refine
> serialization key type [simple type, class java.util.Currency] into java.
> lang.String; types not related
> at com.fasterxml.jackson.databind.AnnotationIntrospector.refine
> SerializationType(AnnotationIntrospector.java:891)
> at com.fasterxml.jackson.databind.ser.PropertyBuilder.findSeria
> lizationType(PropertyBuilder.java:188)
> at com.fasterxml.jackson.databind.ser.PropertyBuilder.buildWriter(
> PropertyBuilder.java:75)
> at com.fasterxml.jackson.databind.ser.BeanSerializerFactory._
> constructWriter(BeanSerializerFactory.java:818)
> at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.fin
> dBeanProperties(BeanSerializerFactory.java:609)
> at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.con
> structBeanSerializer(BeanSerializerFactory.java:390)
> at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.fin
> dBeanSerializer(BeanSerializerFactory.java:273)
> at com.fasterxml.jackson.databind.ser.BeanSerializerFactory._
> createSerializer2(BeanSerializerFactory.java:225)
> at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.cre
> ateSerializer(BeanSerializerFactory.java:159)
> at com.fasterxml.jackson.databind.SerializerProvider._
> createUntypedSerializer(SerializerProvider.java:1272)
> at com.fasterxml.jackson.databind.SerializerProvider._
> createAndCacheUntypedSerializer(SerializerProvider.java:1222)
> at com.fasterxml.jackson.databind.SerializerProvider.findValueS
> erializer(SerializerProvider.java:499)
> at com.fasterxml.jackson.databind.SerializerProvider.findTypedV
> alueSerializer(SerializerProvider.java:697)
> at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.
> serializeValue(DefaultSerializerProvider.java:270)
> at com.fasterxml.jackson.databind.ObjectMapper._
> configAndWriteValue(ObjectMapper.java:3672)
> at com.fasterxml.jackson.databind.ObjectMapper.writeValue(Objec
> tMapper.java:3030)
>
>
>
>
> --
> 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 jackson-user+unsubscr...@googlegroups.com.
> To post to this group, send email to jackson-user@googlegroups.com.
> 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 jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [jackson-user] How to access TypeResolutionContext in jackson 2.8.1

2016-08-11 Thread JonyD
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);


>

-- 
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 jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [jackson-user] How to access TypeResolutionContext in jackson 2.8.1

2016-08-11 Thread JonyD
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 > 
> 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  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 jackson-user...@googlegroups.com .
>> To post to this group, send email to jackso...@googlegroups.com 
>> .
>> 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, se

[jackson-user] Deprecated findSerializationType might be breaking refineSerializationType (v2.8.1)

2016-08-11 Thread JonyD
In 
https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java
the method findSerializationType is deprecated since v2.7 and returns 
always null.
The method refineSerializationType (which is the new method that should be 
used instead of findSerializationType) uses/calls the findSerializationType 
in some parts with logic [if(... ].
I think this makes refineSerializationType broken.

I get the following exception in a custom Serialization:
com.fasterxml.jackson.databind.JsonMappingException: Can not refine 
serialization key type [simple type, class java.util.Currency] into java.
lang.String; types not related
at com.fasterxml.jackson.databind.AnnotationIntrospector.
refineSerializationType(AnnotationIntrospector.java:891)
at com.fasterxml.jackson.databind.ser.PropertyBuilder.
findSerializationType(PropertyBuilder.java:188)
at com.fasterxml.jackson.databind.ser.PropertyBuilder.buildWriter(
PropertyBuilder.java:75)
at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.
_constructWriter(BeanSerializerFactory.java:818)
at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.
findBeanProperties(BeanSerializerFactory.java:609)
at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.
constructBeanSerializer(BeanSerializerFactory.java:390)
at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.
findBeanSerializer(BeanSerializerFactory.java:273)
at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.
_createSerializer2(BeanSerializerFactory.java:225)
at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.
createSerializer(BeanSerializerFactory.java:159)
at com.fasterxml.jackson.databind.SerializerProvider.
_createUntypedSerializer(SerializerProvider.java:1272)
at com.fasterxml.jackson.databind.SerializerProvider.
_createAndCacheUntypedSerializer(SerializerProvider.java:1222)
at com.fasterxml.jackson.databind.SerializerProvider.
findValueSerializer(SerializerProvider.java:499)
at com.fasterxml.jackson.databind.SerializerProvider.
findTypedValueSerializer(SerializerProvider.java:697)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.
serializeValue(DefaultSerializerProvider.java:270)
at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(
ObjectMapper.java:3672)
at com.fasterxml.jackson.databind.ObjectMapper.writeValue(
ObjectMapper.java:3030)




-- 
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 jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.