Search in sources :

Example 96 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project java-chassis by ServiceComb.

the class AbstractConverter method convert.

@Override
public JavaType convert(ClassLoader classLoader, String packageName, Swagger swagger, Object def) {
    Map<String, Object> vendorExtensions = findVendorExtensions(def);
    JavaType javaType = getJavaTypeByVendorExtensions(classLoader, vendorExtensions);
    if (javaType != null) {
        return javaType;
    }
    return doConvert(classLoader, packageName, swagger, def);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Example 97 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project java-chassis by ServiceComb.

the class ConverterMgr method initTypeFormatMap.

private static void initTypeFormatMap() {
    try {
        for (Entry<Class<? extends Property>, JavaType> entry : PROPERTY_MAP.entrySet()) {
            Property property = entry.getKey().newInstance();
            String key = genTypeFormatKey(property.getType(), property.getFormat());
            TYPE_FORMAT_MAP.put(key, entry.getValue());
        }
    } catch (Throwable e) {
        throw new Error(e);
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) ShortProperty(io.servicecomb.swagger.extend.property.ShortProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) ByteProperty(io.servicecomb.swagger.extend.property.ByteProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty)

Example 98 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project java-chassis by ServiceComb.

the class ModelImplConverter method doConvert.

@Override
public JavaType doConvert(ClassLoader classLoader, String packageName, Swagger swagger, Object model) {
    ModelImpl modelImpl = (ModelImpl) model;
    JavaType javaType = ConverterMgr.findJavaType(modelImpl.getType(), modelImpl.getFormat());
    if (javaType != null) {
        return javaType;
    }
    if (modelImpl.getReference() != null) {
        return ConverterMgr.findByRef(classLoader, packageName, swagger, modelImpl.getReference());
    }
    // 根据name、property动态生成class
    if (packageName == null) {
        throw new Error("packageName should not be null");
    }
    String clsName = packageName + "." + modelImpl.getName();
    Class<?> cls = ClassUtils.getOrCreateClass(classLoader, packageName, swagger, modelImpl, clsName);
    return TypeFactory.defaultInstance().constructType(cls);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ModelImpl(io.swagger.models.ModelImpl)

Example 99 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project java-chassis by ServiceComb.

the class ArrayPropertyConverter method findJavaType.

public static JavaType findJavaType(ClassLoader classLoader, String packageName, Swagger swagger, Property itemProperty, Boolean uniqueItems) {
    JavaType itemJavaType = ConverterMgr.findJavaType(classLoader, packageName, swagger, itemProperty);
    @SuppressWarnings("rawtypes") Class<? extends Collection> collectionClass = List.class;
    if (Boolean.TRUE.equals(uniqueItems)) {
        collectionClass = Set.class;
    }
    return TypeFactory.defaultInstance().constructCollectionType(collectionClass, itemJavaType);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) List(java.util.List)

Example 100 with JavaType

use of com.fasterxml.jackson.databind.JavaType in project java-chassis by ServiceComb.

the class StandardResultCodec method init.

@Override
public void init(ProtobufSchema schema, Type... types) {
    writer = ProtobufManager.getMapper().writer(schema);
    reader = ProtobufManager.getMapper().reader(schema);
    // 需要考虑void场景
    if (types.length == 1) {
        JavaType javaType = TypeFactory.defaultInstance().constructType(types[0]);
        writer = writer.forType(javaType);
        reader = reader.forType(javaType);
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType)

Aggregations

JavaType (com.fasterxml.jackson.databind.JavaType)106 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 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 ArrayList (java.util.ArrayList)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 ClassConfig (io.servicecomb.common.javassist.ClassConfig)3 ModelImpl (io.swagger.models.ModelImpl)3 ArrayProperty (io.swagger.models.properties.ArrayProperty)3