Example usage for com.fasterxml.jackson.databind.type ArrayType getContentType

List of usage examples for com.fasterxml.jackson.databind.type ArrayType getContentType

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.type ArrayType getContentType.

Prototype

public JavaType getContentType() 

Source Link

Usage

From source file:com.github.jasonruckman.sidney.core.JavaTypeRefBuilder.java

public static TypeRef buildTypeRef(Type type, TypeBindings parentBindings, Field field) {
    JavaType jt;//  w  w  w  . j  av a  2 s.  c o m
    TypeBindings typeBindings;

    typeBindings = Types.binding(type, parentBindings);
    jt = Types.type(type, parentBindings);
    TypeRef ref;
    if (field == null) {
        ref = new TypeRef(jt.getRawClass());
    } else {
        Hint hint = field.getAnnotation(Hint.class);
        if (hint != null) {
            ref = new TypeRef.TypeFieldRef(hint.value(), field);
        } else {
            ref = new TypeRef.TypeFieldRef(jt.getRawClass(), field);
        }
    }

    for (Field subField : Fields.getAllFields(jt.getRawClass())) {
        Type subType = subField.getGenericType();
        TypeRef subRef = buildTypeRef(subType, typeBindings, subField);
        ref.addField((TypeRef.TypeFieldRef) subRef);
    }

    if (ParameterizedType.class.isAssignableFrom(type.getClass())) {
        ParameterizedType t = (ParameterizedType) type;
        for (Type actualTypeArg : t.getActualTypeArguments()) {
            ref.addTypeParameter(buildTypeRef(actualTypeArg, parentBindings, null));
        }
    } else if (TypeVariable.class.isAssignableFrom(type.getClass())) {
        TypeVariable t = (TypeVariable) type;
        for (Type typeBound : t.getBounds()) {
            ref.addTypeParameter(buildTypeRef(typeBound, parentBindings, null));
        }
    } else if (GenericArrayType.class.isAssignableFrom(type.getClass())) {
        GenericArrayType t = (GenericArrayType) type;
        ref.addTypeParameter(buildTypeRef(t.getGenericComponentType(), parentBindings, null));
    }

    if (jt.isArrayType() && !GenericArrayType.class.isAssignableFrom(type.getClass())) {
        ArrayType arrType = (ArrayType) jt;
        ref.addTypeParameter(buildTypeRef(arrType.getContentType().getRawClass(), null, null));
    }

    return ref;
}