Search in sources :

Example 11 with JavaType

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

the class ConverterMgr method addInnerConverter.

private static void addInnerConverter(Class<? extends Property> propertyCls) {
    JavaType javaType = PROPERTY_MAP.get(propertyCls);
    if (javaType == null) {
        throw new Error("not support inner property class: " + propertyCls.getName());
    }
    converterMap.put(propertyCls, (classLoader, packageName, swagger, def) -> javaType);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 12 with JavaType

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

the class MapPropertyConverter method doConvert.

@Override
public JavaType doConvert(ClassLoader classLoader, String packageName, Swagger swagger, Object property) {
    MapProperty mapProperty = (MapProperty) property;
    Property valueProperty = mapProperty.getAdditionalProperties();
    JavaType valueJavaType = ConverterMgr.findJavaType(classLoader, packageName, swagger, valueProperty);
    return TypeFactory.defaultInstance().constructMapType(Map.class, TypeFactory.defaultInstance().constructType(String.class), valueJavaType);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) MapProperty(io.swagger.models.properties.MapProperty) MapProperty(io.swagger.models.properties.MapProperty) Property(io.swagger.models.properties.Property)

Example 13 with JavaType

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

the class StringPropertyConverter method getOrCreateEnumByNames.

// 转换并创建enum是小概率事件,没必要double check
private static JavaType getOrCreateEnumByNames(String packageName, List<String> enums) {
    String strEnums = enums.toString();
    synchronized (LOCK) {
        JavaType javaType = enumMap.get(strEnums);
        if (javaType != null) {
            return javaType;
        }
        String enumClsName = packageName + ".Enum" + enumMap.size();
        @SuppressWarnings("rawtypes") Class<? extends Enum> enumCls = JavassistUtils.createEnum(enumClsName, enums);
        javaType = TypeFactory.defaultInstance().constructType(enumCls);
        enumMap.put(strEnums, javaType);
        return javaType;
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 14 with JavaType

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

the class TypeBindings method findType.

/*
    /**********************************************************
    /* Accesors
    /**********************************************************
     */
public JavaType findType(String name, boolean mustFind) {
    if (_bindings == null) {
        _resolve();
    }
    JavaType t = _bindings.get(name);
    if (t != null) {
        return t;
    }
    if (_placeholders != null && _placeholders.contains(name)) {
        return UNBOUND;
    }
    if (_parentBindings != null) {
        return _parentBindings.findType(name, mustFind);
    }
    /* 18-Feb-2011, tatu: There are some tricky type bindings within
         *   java.util, such as HashMap$KeySet; so let's punt the problem
         *   (honestly not sure what to do -- they are unbound for good, I think)
         */
    if (_contextClass != null) {
        if (ClassUtil.getEnclosingClass(_contextClass) != null) {
            //   (which will also cover 'java.util' type cases...
            if (!Modifier.isStatic(_contextClass.getModifiers())) {
                return UNBOUND;
            }
        }
    }
    if (!mustFind) {
        return null;
    }
    String className;
    if (_contextClass != null) {
        className = _contextClass.getName();
    } else if (_contextType != null) {
        className = _contextType.toString();
    } else {
        className = "UNKNOWN";
    }
    throw new IllegalArgumentException("Type variable '" + name + "' can not be resolved (with context of class " + className + ")");
//t = UNBOUND;                
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 15 with JavaType

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

the class TypeBindings method _resolve.

protected void _resolve() {
    _resolveBindings(_contextClass);
    // finally: may have root level type info too
    if (_contextType != null) {
        int count = _contextType.containedTypeCount();
        if (count > 0) {
            for (int i = 0; i < count; ++i) {
                String name = _contextType.containedTypeName(i);
                JavaType type = _contextType.containedType(i);
                addBinding(name, type);
            }
        }
    }
    // nothing bound? mark with empty map to prevent further calls
    if (_bindings == null) {
        _bindings = Collections.emptyMap();
    }
}
Also used : 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