Search in sources :

Example 21 with JavaType

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.

the class UnwrappingBeanPropertyWriter method _findAndAddDynamic.

/*
    /**********************************************************
    /* Overrides: internal, other
    /**********************************************************
     */
// need to override as we must get unwrapping instance...
@Override
protected JsonSerializer<Object> _findAndAddDynamic(PropertySerializerMap map, Class<?> type, SerializerProvider provider) throws JsonMappingException {
    JsonSerializer<Object> serializer;
    if (_nonTrivialBaseType != null) {
        JavaType subtype = provider.constructSpecializedType(_nonTrivialBaseType, type);
        serializer = provider.findValueSerializer(subtype, this);
    } else {
        serializer = provider.findValueSerializer(type, this);
    }
    NameTransformer t = _nameTransformer;
    if (serializer.isUnwrappingSerializer()) {
        t = NameTransformer.chainedTransformer(t, ((UnwrappingBeanSerializer) serializer)._nameTransformer);
    }
    serializer = serializer.unwrappingSerializer(t);
    _dynamicSerializers = _dynamicSerializers.newWith(type, serializer);
    return serializer;
}
Also used : NameTransformer(com.fasterxml.jackson.databind.util.NameTransformer) JavaType(com.fasterxml.jackson.databind.JavaType)

Example 22 with JavaType

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.

the class StdConverter method _findConverterType.

protected JavaType _findConverterType(TypeFactory tf) {
    JavaType thisType = tf.constructType(getClass());
    JavaType convType = thisType.findSuperType(Converter.class);
    if (convType == null || convType.containedTypeCount() < 2) {
        throw new IllegalStateException("Can not find OUT type parameter for Converter of type " + getClass().getName());
    }
    return convType;
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 23 with JavaType

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.

the class TypeFactory method _fromClass.

/**
     * @param bindings Mapping of formal parameter declarations (for generic
     *   types) into actual types
     */
protected JavaType _fromClass(ClassStack context, Class<?> rawType, TypeBindings bindings) {
    // Very first thing: small set of core types we know well:
    JavaType result = _findWellKnownSimple(rawType);
    if (result != null) {
        return result;
    }
    // Barring that, we may have recently constructed an instance
    final Object key;
    if ((bindings == null) || bindings.isEmpty()) {
        key = rawType;
    } else {
        key = bindings.asKey(rawType);
    }
    // ok, cache object is synced
    result = _typeCache.get(key);
    if (result != null) {
        return result;
    }
    // 15-Oct-2015, tatu: recursive reference?
    if (context == null) {
        context = new ClassStack(rawType);
    } else {
        ClassStack prev = context.find(rawType);
        if (prev != null) {
            // Self-reference: needs special handling, then...
            ResolvedRecursiveType selfRef = new ResolvedRecursiveType(rawType, EMPTY_BINDINGS);
            prev.addSelfReference(selfRef);
            return selfRef;
        }
        // no, but need to update context to allow for proper cycle resolution
        context = context.child(rawType);
    }
    // First: do we have an array type?
    if (rawType.isArray()) {
        result = ArrayType.construct(_fromAny(context, rawType.getComponentType(), bindings), bindings);
    } else {
        // If not, need to proceed by first resolving parent type hierarchy
        JavaType superClass;
        JavaType[] superInterfaces;
        if (rawType.isInterface()) {
            superClass = null;
            superInterfaces = _resolveSuperInterfaces(context, rawType, bindings);
        } else {
            // Note: even Enums can implement interfaces, so can not drop those
            superClass = _resolveSuperClass(context, rawType, bindings);
            superInterfaces = _resolveSuperInterfaces(context, rawType, bindings);
        }
        // 19-Oct-2015, tatu: Bit messy, but we need to 'fix' java.util.Properties here...
        if (rawType == Properties.class) {
            result = MapType.construct(rawType, bindings, superClass, superInterfaces, CORE_TYPE_STRING, CORE_TYPE_STRING);
        } else // super-type if refinement is all that is needed?
        if (superClass != null) {
            result = superClass.refine(rawType, bindings, superClass, superInterfaces);
        }
        // if not, perhaps we are now resolving a well-known class or interface?
        if (result == null) {
            result = _fromWellKnownClass(context, rawType, bindings, superClass, superInterfaces);
            if (result == null) {
                result = _fromWellKnownInterface(context, rawType, bindings, superClass, superInterfaces);
                if (result == null) {
                    // but if nothing else, "simple" class for now:
                    result = _newSimpleType(rawType, bindings, superClass, superInterfaces);
                }
            }
        }
    }
    context.resolveSelfReferences(result);
    //     cache anything with partially resolved `ResolvedRecursiveType`... so maybe improve
    if (!result.hasHandlers()) {
        // cache object syncs
        _typeCache.putIfAbsent(key, result);
    }
    return result;
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 24 with JavaType

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.

the class TypeFactory method constructMapType.

/**
     * Method for constructing a {@link MapType} instance
     *<p>
     * NOTE: type modifiers are NOT called on constructed type itself; but are called
     * for contained types.
     */
public MapType constructMapType(Class<? extends Map> mapClass, Class<?> keyClass, Class<?> valueClass) {
    JavaType kt, vt;
    if (mapClass == Properties.class) {
        kt = vt = CORE_TYPE_STRING;
    } else {
        kt = _fromClass(null, keyClass, EMPTY_BINDINGS);
        vt = _fromClass(null, valueClass, EMPTY_BINDINGS);
    }
    return constructMapType(mapClass, kt, vt);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 25 with JavaType

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.

the class TypeFactory method _resolveSuperInterfaces.

protected JavaType[] _resolveSuperInterfaces(ClassStack context, Class<?> rawType, TypeBindings parentBindings) {
    Type[] types = ClassUtil.getGenericInterfaces(rawType);
    if (types == null || types.length == 0) {
        return NO_TYPES;
    }
    int len = types.length;
    JavaType[] resolved = new JavaType[len];
    for (int i = 0; i < len; ++i) {
        Type type = types[i];
        resolved[i] = _fromAny(context, type, parentBindings);
    }
    return resolved;
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) JavaType(com.fasterxml.jackson.databind.JavaType)

Aggregations

JavaType (com.fasterxml.jackson.databind.JavaType)322 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)36 Test (org.junit.Test)29 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)25 IOException (java.io.IOException)25 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)22 ArrayList (java.util.ArrayList)21 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)17 Property (io.swagger.models.properties.Property)16 List (java.util.List)16 Map (java.util.Map)14 ModelImpl (io.swagger.models.ModelImpl)13 StringProperty (io.swagger.models.properties.StringProperty)13 Annotation (java.lang.annotation.Annotation)12 Method (java.lang.reflect.Method)11 Type (java.lang.reflect.Type)11 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)10 BodyParameter (io.swagger.models.parameters.BodyParameter)10 MapProperty (io.swagger.models.properties.MapProperty)10 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)9