public final <A extends Annotation> boolean hasAnnotation(Class<A> acls) { return getAnnotation(acls) != null; }
@Override public boolean hasCreatorAnnotation(Annotated a) { /* No dedicated disabling; regular @JsonIgnore used * if needs to be ignored (and if so, is handled prior * to this method getting called) */ return a.hasAnnotation(JsonCreator.class); }
/** * Full generic type of the annotated element; definition * of what exactly this means depends on sub-class. */ public JavaType getType(TypeBindings context) { return context.resolveType(getGenericType()); }
/** * Fluent factory method that will construct a new instance that uses * annotations from specified {@link Annotated} as fallback annotations * * @since 1.9 */ public final Annotated withFallBackAnnotationsFrom(Annotated annotated) { return withAnnotations(AnnotationMap.merge(getAllAnnotations(), annotated.getAllAnnotations())); }
@Override public Object findSerializer(Annotated a) { /* 21-May-2009, tatu: Slight change; primary annotation is now * @JsonSerialize; @JsonUseSerializer is deprecated */ JsonSerialize ann = a.getAnnotation(JsonSerialize.class); if (ann != null) { Class<? extends JsonSerializer<?>> serClass = ann.using(); if (serClass != JsonSerializer.None.class) { return serClass; } } /* 18-Oct-2010, tatu: [JACKSON-351] @JsonRawValue handled just here, for now; * if we need to get raw indicator from other sources need to add * separate accessor within {@link AnnotationIntrospector} interface. */ JsonRawValue annRaw = a.getAnnotation(JsonRawValue.class); if ((annRaw != null) && annRaw.value()) { // let's construct instance with nominal type: Class<?> cls = a.getRawType(); return new RawSerializer<Object>(cls); } return null; }
@Override public Object findDeserializer(Annotated am) { if (am.hasAnnotation(ObjectId.class)) { return findObjectIdDeserializer(deserializationConfig.getTypeFactory().constructType(am.getGenericType())); } return null; }
/** * Helper method used to encapsulate details of annotation-based type * coercion * * @since 1.8 */ @SuppressWarnings("unchecked") protected <T extends JavaType> T modifyTypeByAnnotation(SerializationConfig config, Annotated a, T type) { // first: let's check class for the instance itself: Class<?> superclass = config.getAnnotationIntrospector().findSerializationType(a); if (superclass != null) { try { type = (T) type.widenBy(superclass); } catch (IllegalArgumentException iae) { throw new IllegalArgumentException("Failed to widen type "+type+" with concrete-type annotation (value "+superclass.getName()+"), method '"+a.getName()+"': "+iae.getMessage()); } } return modifySecondaryTypesByAnnotation(config, a, type); }
public final boolean isPublic() { return Modifier.isPublic(getModifiers()); }
protected Class<?> findSerializationType(Annotated a, boolean useStaticTyping) { // [JACKSON-120]: Check to see if serialization type is fixed Class<?> serializationType = _annotationIntrospector.findSerializationType(a); if (serializationType != null) { // Must be a super type... Class<?> type = a.getType(); if (!serializationType.isAssignableFrom(type)) { throw new IllegalArgumentException("Illegal concrete-type annotation for method '"+a.getName()+"': class "+serializationType.getName()+" not a super-type of (declared) class "+type.getName()); } return serializationType; } /* [JACKSON-114]: if using static typing, declared type is known * to be the type... */ JsonSerialize.Typing typing = _annotationIntrospector.findSerializationTyping(a); if (typing != null) { useStaticTyping = (typing == JsonSerialize.Typing.STATIC); } if (useStaticTyping) { return a.getType(); } return null; }
@Override public Object findSerializer(Annotated a) { /* 21-May-2009, tatu: Slight change; primary annotation is now * @JsonSerialize; @JsonUseSerializer is deprecated */ JsonSerialize ann = a.getAnnotation(JsonSerialize.class); if (ann != null) { Class<? extends JsonSerializer<?>> serClass = ann.using(); if (serClass != JsonSerializer.None.class) { return serClass; } } /* 18-Oct-2010, tatu: [JACKSON-351] @JsonRawValue handled just here, for now; * if we need to get raw indicator from other sources need to add * separate accessor within {@link AnnotationIntrospector} interface. */ JsonRawValue annRaw = a.getAnnotation(JsonRawValue.class); if ((annRaw != null) && annRaw.value()) { // let's construct instance with nominal type: Class<?> cls = a.getRawType(); return new RawSerializer<Object>(cls); } return null; }
@Override public Object findDeserializer(Annotated am) { if (am.hasAnnotation(ObjectId.class)) { return findObjectIdDeserializer(deserializationConfig.getTypeFactory().constructType(am.getGenericType())); } return null; }
throw new IllegalArgumentException("Illegal concrete-type annotation for method '"+a.getName()+"': class "+serClass.getName()+" not a super-type of (declared) class "+rawDeclared.getName());
/** * Fluent factory method that will construct a new instance that uses * annotations from specified {@link Annotated} as fallback annotations * * @since 1.9 */ public final Annotated withFallBackAnnotationsFrom(Annotated annotated) { return withAnnotations(AnnotationMap.merge(getAllAnnotations(), annotated.getAllAnnotations())); }
public final boolean isPublic() { return Modifier.isPublic(getModifiers()); }
@Override public Class<? extends JsonDeserializer<?>> findContentDeserializer(Annotated a) { JsonDeserialize ann = a.getAnnotation(JsonDeserialize.class); if (ann != null) { Class<? extends JsonDeserializer<?>> deserClass = ann.contentUsing(); if (deserClass != JsonDeserializer.None.class) { return deserClass; } } return null; }
@Override public Object findSerializer(Annotated a) { /* 21-May-2009, tatu: Slight change; primary annotation is now * @JsonSerialize; @JsonUseSerializer is deprecated */ JsonSerialize ann = a.getAnnotation(JsonSerialize.class); if (ann != null) { Class<? extends JsonSerializer<?>> serClass = ann.using(); if (serClass != JsonSerializer.None.class) { return serClass; } } /* 18-Oct-2010, tatu: [JACKSON-351] @JsonRawValue handled just here, for now; * if we need to get raw indicator from other sources need to add * separate accessor within {@link AnnotationIntrospector} interface. */ JsonRawValue annRaw = a.getAnnotation(JsonRawValue.class); if ((annRaw != null) && annRaw.value()) { // let's construct instance with nominal type: Class<?> cls = a.getRawType(); return new RawSerializer<Object>(cls); } return null; }
@Override public Class findContentDeserializer(Annotated am) { if (am.hasAnnotation(ObjectId.class)) { JavaType type = deserializationConfig.getTypeFactory().constructType(am.getGenericType()); if (type.isCollectionLikeType()) { return findObjectIdDeserializer(type.containedType(0)); } else if (type.isMapLikeType()) { return findObjectIdDeserializer(type.containedType(1)); } } return null; }
type = (T) type.narrowBy(subclass); } catch (IllegalArgumentException iae) { throw new JsonMappingException("Failed to narrow type "+type+" with concrete-type annotation (value "+subclass.getName()+"), method '"+a.getName()+"': "+iae.getMessage(), null, iae);
@Override public boolean hasCreatorAnnotation(Annotated a) { /* No dedicated disabling; regular @JsonIgnore used * if needs to be ignored (and if so, is handled prior * to this method getting called) */ return a.hasAnnotation(JsonCreator.class); }
/** * Fluent factory method that will construct a new instance that uses * annotations from specified {@link Annotated} as fallback annotations * * @since 1.9 */ public final Annotated withFallBackAnnotationsFrom(Annotated annotated) { return withAnnotations(AnnotationMap.merge(getAllAnnotations(), annotated.getAllAnnotations())); }