On Wed, Dec 27, 2017 at 9:33 AM, Bojan Tomic <[email protected]> wrote: > Just for the sake of experimentation, I've cobbled together the following > wrapper class: > > class AnnotatedJavaType extends JavaType implements AnnotatedElement { > > private final JavaType base; > private final Annotation[] annotations; > > AnnotatedJavaType(JavaType base, Annotation[] annotations) { ... } > > //all methods simply delegate to this.base > } > > > > And the corresponding TypeFactory wrapper: > > class AnnotatedTypeFactory { > > JavaType construct(AnnotatedType type, TypeFactory typeFactory) { > if (type instanceof AnnotatedParameterizedType) { > JavaType[] args = Arrays.stream(((AnnotatedParameterizedType) > type).getAnnotatedActualTypeArguments()) > .map(arg -> fromJavaType(arg, typeFactory)) > .toArray(JavaType[]::new); > > TypeBindings bindings = > TypeBindings.create(ClassUtils.getRawType(type.getType()), args); > > return new AnnotatedJavaType(typeFactory.constructType(type.getType(), > bindings), type.getAnnotations()); > } > > //handle wildcards, arrays, variables in the similar fashion > > return new AnnotatedJavaType(typeFactory.constructType(type.getType()), > type.getAnnotations()); > } > } > > Amusingly enough, it works! I'd never keep it in my code base, but it was an > interesting experiment. > > If the functionality I'm after is impossible (and I really hope it is not), > would you be open to a contribution? I'd of course need some > consultation/guidance on the approach, but would be happy to develop it.
As per my other note, this would need to be in Jackson 3.0 I think, due to multiple reasons. I am bit hesitant to say much more since I really fear all complexity that would come from trying to create parallel annotation processing system. I can see some benefits from type annotations, but it wouldn't come for free, if we are talking about whole AnnotationIntrospector style system. However: if the idea would be to do something simpler -- I don't really see need for full AnnotationIntrospector in this case, to be honest -- for example, simply keep track of annotations for type, offer access... well, that seems quite doable and useful. If so, `JavaType` could just have `findAnnotation(Class<?> type)` method or something? -+ Tatu +- > > > > > On Wednesday, December 27, 2017 at 11:34:37 AM UTC+1, Bojan Tomic wrote: >> >> I have a rather exotic use-case that I have to support. Types annotated >> with @Id need custom deserialization logic, e.g. the value should be Base64 >> decoded before deserializing it (not the only case). >> >> This means a type such as List<@Id Key> will be represented as a list of >> Base64 Strings that I deserialize using my custom logic. >> >> I originally have an AnnotatedType that I convert to JavaType using >> TypeFactory.constructType(annotatedType.getType()) prior to deserialization, >> which of course looses all the annotations. >> Later, in my custom Deserializers instance, in its various >> findXXXDeserializer methods, I have no way to find the correct deserializer >> as the annotations needed for the decision are gone... >> >> I was hoping the JDK8 module would have it's own TypeFactory-like >> mechanism to construct JavaType subclasses that preserve the annotations >> from AnnotatedTypes (e.g. >> AnnotatedTypeFactory.constructType(annotatedType)), but it doesn't seem to >> be the case. >> >> Is there any way at all to implement what I'm after? > > -- > 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. -- 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.
