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