Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.codehaus.jackson.map.introspect;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.jackson.annotate.*;
import org.codehaus.jackson.map.*;
import org.codehaus.jackson.map.annotate.*;
import org.codehaus.jackson.map.jsontype.NamedType;
import org.codehaus.jackson.map.jsontype.TypeIdResolver;
import org.codehaus.jackson.map.jsontype.TypeResolverBuilder;
import org.codehaus.jackson.map.jsontype.impl.StdTypeResolverBuilder;
import org.codehaus.jackson.map.ser.std.RawSerializer;
import org.codehaus.jackson.type.JavaType;
/**
* {@link AnnotationIntrospector} implementation that handles standard
* Jackson annotations.
*/
public class JacksonAnnotationIntrospector
extends AnnotationIntrospector
{
public JacksonAnnotationIntrospector() { }
/*
/**********************************************************
/* General annotation properties
/**********************************************************
*/
@Override
public boolean isHandled(Annotation ann)
{
Class extends Annotation> acls = ann.annotationType();
/* 16-May-2009, tatu: used to check this like so...
final String JACKSON_PKG_PREFIX = "org.codehaus.jackson";
Package pkg = acls.getPackage();
return (pkg != null) && (pkg.getName().startsWith(JACKSON_PKG_PREFIX));
*/
// but this is more reliable, now that we have tag annotation:
return acls.getAnnotation(JacksonAnnotation.class) != null;
}
/*
/**********************************************************
/* General annotations
/**********************************************************
*/
@Override
public String findEnumValue(Enum> value)
{
return value.name();
}
/*
/**********************************************************
/* General class annotations
/**********************************************************
*/
@Override
public Boolean findCachability(AnnotatedClass ac)
{
JsonCachable ann = ac.getAnnotation(JsonCachable.class);
if (ann == null) {
return null;
}
return ann.value() ? Boolean.TRUE : Boolean.FALSE;
}
@Override
public String findRootName(AnnotatedClass ac)
{
JsonRootName ann = ac.getAnnotation(JsonRootName.class);
return (ann == null) ? null : ann.value();
}
@Override
public String[] findPropertiesToIgnore(AnnotatedClass ac) {
JsonIgnoreProperties ignore = ac.getAnnotation(JsonIgnoreProperties.class);
return (ignore == null) ? null : ignore.value();
}
@Override
public Boolean findIgnoreUnknownProperties(AnnotatedClass ac) {
JsonIgnoreProperties ignore = ac.getAnnotation(JsonIgnoreProperties.class);
return (ignore == null) ? null : ignore.ignoreUnknown();
}
@Override
public Boolean isIgnorableType(AnnotatedClass ac) {
JsonIgnoreType ignore = ac.getAnnotation(JsonIgnoreType.class);
return (ignore == null) ? null : ignore.value();
}
@Override
public Object findFilterId(AnnotatedClass ac)
{
JsonFilter ann = ac.getAnnotation(JsonFilter.class);
if (ann != null) {
String id = ann.value();
// Empty String is same as not having annotation, to allow overrides
if (id.length() > 0) {
return id;
}
}
return null;
}
/*
/**********************************************************
/* Property auto-detection
/**********************************************************
*/
@Override
public VisibilityChecker> findAutoDetectVisibility(AnnotatedClass ac,
VisibilityChecker> checker)
{
JsonAutoDetect ann = ac.getAnnotation(JsonAutoDetect.class);
return (ann == null) ? checker : checker.with(ann);
}
/*
/**********************************************************
/* General member (field, method/constructor) annotations
/**********************************************************
*/
// @since 1.6
@Override
public ReferenceProperty findReferenceType(AnnotatedMember member)
{
JsonManagedReference ref1 = member.getAnnotation(JsonManagedReference.class);
if (ref1 != null) {
return AnnotationIntrospector.ReferenceProperty.managed(ref1.value());
}
JsonBackReference ref2 = member.getAnnotation(JsonBackReference.class);
if (ref2 != null) {
return AnnotationIntrospector.ReferenceProperty.back(ref2.value());
}
return null;
}
@Override
public Boolean shouldUnwrapProperty(AnnotatedMember member)
{
JsonUnwrapped ann = member.getAnnotation(JsonUnwrapped.class);
// if not enabled, just means annotation is not enabled; not necessarily
// that unwrapping should not be done (relevant when using chained introspectors)
return (ann != null && ann.enabled()) ? Boolean.TRUE : null;
}
@Override
public boolean hasIgnoreMarker(AnnotatedMember m) {
return _isIgnorable(m);
}
@Override
public Object findInjectableValueId(AnnotatedMember m)
{
JacksonInject ann = m.getAnnotation(JacksonInject.class);
if (ann == null) {
return null;
}
/* Empty String means that we should use name of declared
* value class.
*/
String id = ann.value();
if (id.length() == 0) {
// slight complication; for setters, type
if (!(m instanceof AnnotatedMethod)) {
return m.getRawType().getName();
}
AnnotatedMethod am = (AnnotatedMethod) m;
if (am.getParameterCount() == 0) {
return m.getRawType().getName();
}
return am.getParameterClass(0).getName();
}
return id;
}
/*
/**********************************************************
/* Class annotations for PM type handling (1.5+)
/**********************************************************
*/
@Override
public TypeResolverBuilder> findTypeResolver(MapperConfig> config,
AnnotatedClass ac, JavaType baseType)
{
return _findTypeResolver(config, ac, baseType);
}
/**
* Since 1.7, it is possible to use {@link JsonTypeInfo} from a property too.
*/
@Override
public TypeResolverBuilder> findPropertyTypeResolver(MapperConfig> config,
AnnotatedMember am, JavaType baseType)
{
/* As per definition of @JsonTypeInfo, should only apply to contents of container
* (collection, map) types, not container types themselves:
*/
if (baseType.isContainerType()) return null;
// No per-member type overrides (yet)
return _findTypeResolver(config, am, baseType);
}
/**
* Since 1.7, it is possible to use {@link JsonTypeInfo} from a property too.
*/
@Override
public TypeResolverBuilder> findPropertyContentTypeResolver(MapperConfig> config,
AnnotatedMember am, JavaType containerType)
{
/* First: let's ensure property is a container type: caller should have
* verified but just to be sure
*/
if (!containerType.isContainerType()) {
throw new IllegalArgumentException("Must call method with a container type (got "+containerType+")");
}
return _findTypeResolver(config, am, containerType);
}
@Override
public List findSubtypes(Annotated a)
{
JsonSubTypes t = a.getAnnotation(JsonSubTypes.class);
if (t == null) return null;
JsonSubTypes.Type[] types = t.value();
ArrayList result = new ArrayList(types.length);
for (JsonSubTypes.Type type : types) {
result.add(new NamedType(type.value(), type.name()));
}
return result;
}
@Override
public String findTypeName(AnnotatedClass ac)
{
JsonTypeName tn = ac.getAnnotation(JsonTypeName.class);
return (tn == null) ? null : tn.value();
}
/*
/**********************************************************
/* General method annotations
/**********************************************************
*/
@Override
public boolean isIgnorableMethod(AnnotatedMethod m) {
return _isIgnorable(m);
}
@Override
public boolean isIgnorableConstructor(AnnotatedConstructor c) {
return _isIgnorable(c);
}
/*
/**********************************************************
/* General field annotations
/**********************************************************
*/
@Override
public boolean isIgnorableField(AnnotatedField f) {
return _isIgnorable(f);
}
/*
/**********************************************************
/* Serialization: general annotations
/**********************************************************
*/
@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