com.fasterxml.jackson.databind.JavaType#getBindings ( )源码实例Demo

下面列出了com.fasterxml.jackson.databind.JavaType#getBindings ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) {
	JavaType javaType = Json.mapper().constructType(type.getType());
	if (javaType != null) {
		Class<?> cls = javaType.getRawClass();
		if (isResponseTypeWrapper(cls)) {
			JavaType innerType = javaType.getBindings().getBoundType(0);
			if (innerType == null)
				return new StringSchema();
			else if (innerType.getBindings() != null && isResponseTypeWrapper(innerType.getRawClass())) {
				type = new AnnotatedType(innerType).jsonViewAnnotation(type.getJsonViewAnnotation()).ctxAnnotations(type.getCtxAnnotations()).resolveAsRef(true);
				return this.resolve(type, context, chain);
			}
			else
				type = new AnnotatedType(innerType).jsonViewAnnotation(type.getJsonViewAnnotation()).ctxAnnotations((type.getCtxAnnotations())).resolveAsRef(true);
		}
		else if (isResponseTypeToIgnore(cls))
			return null;
	}
	return (chain.hasNext()) ? chain.next().resolve(type, context, chain) : null;
}
 
@Override
public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) {
	JavaType javaType = Json.mapper().constructType(type.getType());
	if (javaType != null) {
		Class<?> cls = javaType.getRawClass();
		if (isFluxTypeWrapper(cls)) {
			JavaType innerType = javaType.getBindings().getBoundType(0);
			if (innerType == null)
				return new StringSchema();
			else if (innerType.getBindings() != null && isResponseTypeWrapper(innerType.getRawClass())) {
				type = new AnnotatedType(innerType).jsonViewAnnotation(type.getJsonViewAnnotation()).resolveAsRef(true);
				return this.resolve(type, context, chain);
			}
			else {
				ArrayType arrayType = ArrayType.construct(innerType, null);
				type = new AnnotatedType(arrayType).jsonViewAnnotation(type.getJsonViewAnnotation()).resolveAsRef(true);
			}
		}
	}
	return (chain.hasNext()) ? chain.next().resolve(type, context, chain) : null;
}
 
源代码3 项目: lams   文件: TypeFactory.java
/**
 * @deprecated Since 2.7 (accidentally removed in 2.7.0; added back in 2.7.1)
 */
@Deprecated
public JavaType constructType(Type type, JavaType contextType) {
    TypeBindings bindings;
    if (contextType == null) {
        bindings = EMPTY_BINDINGS;
    } else {
        bindings = contextType.getBindings();
        // 16-Nov-2016, tatu: Unfortunately as per [databind#1456] this can't
        //   be made to work for some cases used to work (even if accidentally);
        //   however, we can try a simple heuristic to increase chances of
        //   compatibility from 2.6 code
        if (type.getClass() != Class.class) {
            // Ok: so, ideally we would test super-interfaces if necessary;
            // but let's assume most if not all cases are for classes.
            while (bindings.isEmpty()) {
                contextType = contextType.getSuperClass();
                if (contextType == null) {
                    break;
                }
                bindings = contextType.getBindings();
            }
        }
    }
    return _fromAny(null, type, bindings);
}
 
源代码4 项目: lams   文件: AnnotatedClassResolver.java
AnnotatedClassResolver(MapperConfig<?> config, JavaType type, MixInResolver r) {
    _config = config;
    _type = type;
    _class = type.getRawClass();
    _mixInResolver = r;
    _bindings = type.getBindings();
    _intr = config.isAnnotationProcessingEnabled()
            ? config.getAnnotationIntrospector() : null;
    _primaryMixin = _config.findMixInClassFor(_class);
}
 
MapDeserializer<T, I, K, V> createDeserializer(JavaType type) {
    List<JavaType> typeParameters = null;
    TypeBindings bindings = type.getBindings();
    if (bindings != null) {
        typeParameters = bindings.getTypeParameters();
    }
    JavaType keyType;
    JavaType valueType;
    if (typeParameters != null && !typeParameters.isEmpty()) {
        if (refKey && refValue) {
            if (typeParameters.size() != 2) {
                throw new IllegalStateException(
                        "type parameters: " + typeParameters + ", expected exactly two");
            }
        } else if (refKey || refValue) {
            if (typeParameters.size() != 1) {
                throw new IllegalStateException(
                        "type parameters: " + typeParameters + ", expected exactly one");
            }
        }
        keyType = refKey ? typeParameters.get(0) : null;
        valueType = refValue ? typeParameters.get(typeParameters.size() - 1) : null;
    } else {
        // `type` is a raw type
        keyType = TypeFactory.unknownType();
        valueType = TypeFactory.unknownType();
    }
    return MapDeserializer.create(keyType, valueType, typeHandlerPair, finish);
}
 
源代码6 项目: lams   文件: TypeFactory.java
/**
 * Factory method that can be used if type information is passed
 * as Java typing returned from <code>getGenericXxx</code> methods
 * (usually for a return or argument type).
 */
protected JavaType _fromAny(ClassStack context, Type type, TypeBindings bindings)
{
    JavaType resultType;

    // simple class?
    if (type instanceof Class<?>) {
        // Important: remove possible bindings since this is type-erased thingy
        resultType = _fromClass(context, (Class<?>) type, EMPTY_BINDINGS);
    }
    // But if not, need to start resolving.
    else if (type instanceof ParameterizedType) {
        resultType = _fromParamType(context, (ParameterizedType) type, bindings);
    }
    else if (type instanceof JavaType) { // [databind#116]
        // no need to modify further if we already had JavaType
        return (JavaType) type;
    }
    else if (type instanceof GenericArrayType) {
        resultType = _fromArrayType(context, (GenericArrayType) type, bindings);
    }
    else if (type instanceof TypeVariable<?>) {
        resultType = _fromVariable(context, (TypeVariable<?>) type, bindings);
    }
    else if (type instanceof WildcardType) {
        resultType = _fromWildcard(context, (WildcardType) type, bindings);
    } else {
        // sanity check
        throw new IllegalArgumentException("Unrecognized Type: "+((type == null) ? "[null]" : type.toString()));
    }
    /* 21-Feb-2016, nateB/tatu: as per [databind#1129] (applied for 2.7.2),
     *   we do need to let all kinds of types to be refined, esp. for Scala module.
     */
    if (_modifiers != null) {
        TypeBindings b = resultType.getBindings();
        if (b == null) {
            b = EMPTY_BINDINGS;
        }
        for (TypeModifier mod : _modifiers) {
            JavaType t = mod.modifyType(resultType, type, b, this);
            if (t == null) {
                throw new IllegalStateException(String.format(
                        "TypeModifier %s (of type %s) return null for type %s",
                        mod, mod.getClass().getName(), resultType));
            }
            resultType = t;
        }
    }
    return resultType;
}
 
源代码7 项目: jackson-modules-base   文件: BeanBuilder.java
protected TypeResolutionContext buildTypeContext(JavaType ctxtType)
{
    return new TypeResolutionContext.Basic(_typeFactory,
            ctxtType.getBindings());
}