Search in sources :

Example 76 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.

the class TestTypeBindings method testRecursiveType.

// for [databind#76]
public void testRecursiveType() {
    TypeFactory tf = TypeFactory.defaultInstance();
    JavaType type = tf.constructType(HashTree.class);
    assertNotNull(type);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 77 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.

the class TestTypeBindings method testInnerType.

/*
    /**********************************************************
    /* Test methods
    /**********************************************************
     */
public void testInnerType() throws Exception {
    TypeFactory tf = TypeFactory.defaultInstance();
    JavaType type = tf.constructType(InnerGenericTyping.InnerClass.class);
    assertEquals(MapType.class, type.getClass());
    JavaType keyType = type.getKeyType();
    assertEquals(Object.class, keyType.getRawClass());
    JavaType valueType = type.getContentType();
    assertEquals(Collection.class, valueType.getRawClass());
    JavaType vt2 = valueType.getContentType();
    assertEquals(Object.class, vt2.getRawClass());
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 78 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.

the class TypeFactory method _referenceType.

private JavaType _referenceType(Class<?> rawClass, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces) {
    List<JavaType> typeParams = bindings.getTypeParameters();
    // ok to have no types ("raw")
    JavaType ct;
    if (typeParams.isEmpty()) {
        ct = _unknownType();
    } else if (typeParams.size() == 1) {
        ct = typeParams.get(0);
    } else {
        throw new IllegalArgumentException("Strange Reference type " + rawClass.getName() + ": can not determine type parameters");
    }
    return ReferenceType.construct(rawClass, bindings, superClass, superInterfaces, ct);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 79 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.

the class TypeFactory method _collectionType.

private JavaType _collectionType(Class<?> rawClass, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces) {
    List<JavaType> typeParams = bindings.getTypeParameters();
    // ok to have no types ("raw")
    JavaType ct;
    if (typeParams.isEmpty()) {
        ct = _unknownType();
    } else if (typeParams.size() == 1) {
        ct = typeParams.get(0);
    } else {
        throw new IllegalArgumentException("Strange Collection type " + rawClass.getName() + ": can not determine type parameters");
    }
    return CollectionType.construct(rawClass, bindings, superClass, superInterfaces, ct);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 80 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.

the class TypeFactory method _fromVariable.

protected JavaType _fromVariable(ClassStack context, TypeVariable<?> var, TypeBindings bindings) {
    // ideally should find it via bindings:
    final String name = var.getName();
    JavaType type = bindings.findBoundType(name);
    if (type != null) {
        return type;
    }
    // into account possible multiple bounds, nor consider upper bounds.
    if (bindings.hasUnbound(name)) {
        return CORE_TYPE_OBJECT;
    }
    bindings = bindings.withUnboundVariable(name);
    Type[] bounds = var.getBounds();
    return _fromAny(context, bounds[0], bindings);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) JavaType(com.fasterxml.jackson.databind.JavaType)

Aggregations

JavaType (com.fasterxml.jackson.databind.JavaType)110 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)10 IOException (java.io.IOException)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)7 ArrayList (java.util.ArrayList)7 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)6 Property (io.swagger.models.properties.Property)6 Test (org.junit.Test)6 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)5 Method (java.lang.reflect.Method)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 StringProperty (io.swagger.models.properties.StringProperty)4 List (java.util.List)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)3 CollectionType (com.fasterxml.jackson.databind.type.CollectionType)3 MapType (com.fasterxml.jackson.databind.type.MapType)3 ClassConfig (io.servicecomb.common.javassist.ClassConfig)3 ModelImpl (io.swagger.models.ModelImpl)3