Search in sources :

Example 11 with JavaType

use of 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 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 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 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 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)264 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)31 Test (org.junit.Test)27 IOException (java.io.IOException)21 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)20 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)17 ArrayList (java.util.ArrayList)17 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)15 Property (io.swagger.models.properties.Property)15 List (java.util.List)15 Map (java.util.Map)13 StringProperty (io.swagger.models.properties.StringProperty)12 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)10 ModelImpl (io.swagger.models.ModelImpl)10 MapProperty (io.swagger.models.properties.MapProperty)10 Method (java.lang.reflect.Method)10 Type (java.lang.reflect.Type)10 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)9 ArrayProperty (io.swagger.models.properties.ArrayProperty)9 IntegerProperty (io.swagger.models.properties.IntegerProperty)9