Search in sources :

Example 86 with JavaType

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

the class SimpleType method buildCanonicalName.

@Override
protected String buildCanonicalName() {
    StringBuilder sb = new StringBuilder();
    sb.append(_class.getName());
    final int count = _bindings.size();
    if (count > 0) {
        sb.append('<');
        for (int i = 0; i < count; ++i) {
            JavaType t = containedType(i);
            if (i > 0) {
                sb.append(',');
            }
            sb.append(t.toCanonical());
        }
        sb.append('>');
    }
    return sb.toString();
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 87 with JavaType

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

the class SimpleType method _narrow.

@Override
@Deprecated
protected JavaType _narrow(Class<?> subclass) {
    if (_class == subclass) {
        return this;
    }
    // TODO: fix in 2.9
    if (!_class.isAssignableFrom(subclass)) {
        /*
            throw new IllegalArgumentException("Class "+subclass.getName()+" not sub-type of "
                    +_class.getName());
                    */
        return new SimpleType(subclass, _bindings, this, _superInterfaces, _valueHandler, _typeHandler, _asStatic);
    }
    // Otherwise, stitch together the hierarchy. First, super-class
    Class<?> next = subclass.getSuperclass();
    if (next == _class) {
        // straight up parent class? Great.
        return new SimpleType(subclass, _bindings, this, _superInterfaces, _valueHandler, _typeHandler, _asStatic);
    }
    if ((next != null) && _class.isAssignableFrom(next)) {
        JavaType superb = _narrow(next);
        return new SimpleType(subclass, _bindings, superb, null, _valueHandler, _typeHandler, _asStatic);
    }
    // if not found, try a super-interface
    Class<?>[] nextI = subclass.getInterfaces();
    for (Class<?> iface : nextI) {
        if (iface == _class) {
            // directly implemented
            return new SimpleType(subclass, _bindings, null, new JavaType[] { this }, _valueHandler, _typeHandler, _asStatic);
        }
        if (_class.isAssignableFrom(iface)) {
            // indirect, so recurse
            JavaType superb = _narrow(iface);
            return new SimpleType(subclass, _bindings, null, new JavaType[] { superb }, _valueHandler, _typeHandler, _asStatic);
        }
    }
    // should not get here but...
    throw new IllegalArgumentException("Internal error: Can not resolve sub-type for Class " + subclass.getName() + " to " + _class.getName());
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 88 with JavaType

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

the class TypeBindings method findBoundType.

/*
    /**********************************************************************
    /* Accessors
    /**********************************************************************
     */
/**
     * Find type bound to specified name, if there is one; returns bound type if so, null if not.
     */
public JavaType findBoundType(String name) {
    for (int i = 0, len = _names.length; i < len; ++i) {
        if (name.equals(_names[i])) {
            JavaType t = _types[i];
            if (t instanceof ResolvedRecursiveType) {
                ResolvedRecursiveType rrt = (ResolvedRecursiveType) t;
                JavaType t2 = rrt.getSelfReferencedType();
                if (t2 != null) {
                    t = t2;
                } else {
                /* 25-Feb-2016, tatu: Looks like a potential problem, but alas
                         *   we have a test where this should NOT fail and things... seem
                         *   to work. So be it.
                         */
                /*
                        throw new IllegalStateException(String.format
("Unresolved ResolvedRecursiveType for parameter '%s' (index #%d; erased type %s)",
name, i, t.getRawClass()));
*/
                }
            }
            return t;
        }
    }
    return null;
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 89 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project retrofit by square.

the class JacksonConverterFactory method responseBodyConverter.

@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
    JavaType javaType = mapper.getTypeFactory().constructType(type);
    ObjectReader reader = mapper.readerFor(javaType);
    return new JacksonResponseBodyConverter<>(reader);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ObjectReader(com.fasterxml.jackson.databind.ObjectReader)

Example 90 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project retrofit by square.

the class JacksonConverterFactory method requestBodyConverter.

@Override
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
    JavaType javaType = mapper.getTypeFactory().constructType(type);
    ObjectWriter writer = mapper.writerFor(javaType);
    return new JacksonRequestBodyConverter<>(writer);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter)

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