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);
}
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);
}
}
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);
}
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);
}
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);
}
}
Aggregations