use of com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.
the class SimpleType method buildCanonicalName.
@Override
protected String buildCanonicalName() {
StringBuilder sb = new StringBuilder();
sb.append(_class.getName());
final int count = _bindings.size();
if (count > 0) {
sb.append('<');
for (int i = 0; i < count; ++i) {
JavaType t = containedType(i);
if (i > 0) {
sb.append(',');
}
sb.append(t.toCanonical());
}
sb.append('>');
}
return sb.toString();
}
use of com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.
the class SimpleType method _narrow.
@Override
@Deprecated
protected JavaType _narrow(Class<?> subclass) {
if (_class == subclass) {
return this;
}
// TODO: fix in 2.9
if (!_class.isAssignableFrom(subclass)) {
/*
throw new IllegalArgumentException("Class "+subclass.getName()+" not sub-type of "
+_class.getName());
*/
return new SimpleType(subclass, _bindings, this, _superInterfaces, _valueHandler, _typeHandler, _asStatic);
}
// Otherwise, stitch together the hierarchy. First, super-class
Class<?> next = subclass.getSuperclass();
if (next == _class) {
// straight up parent class? Great.
return new SimpleType(subclass, _bindings, this, _superInterfaces, _valueHandler, _typeHandler, _asStatic);
}
if ((next != null) && _class.isAssignableFrom(next)) {
JavaType superb = _narrow(next);
return new SimpleType(subclass, _bindings, superb, null, _valueHandler, _typeHandler, _asStatic);
}
// if not found, try a super-interface
Class<?>[] nextI = subclass.getInterfaces();
for (Class<?> iface : nextI) {
if (iface == _class) {
// directly implemented
return new SimpleType(subclass, _bindings, null, new JavaType[] { this }, _valueHandler, _typeHandler, _asStatic);
}
if (_class.isAssignableFrom(iface)) {
// indirect, so recurse
JavaType superb = _narrow(iface);
return new SimpleType(subclass, _bindings, null, new JavaType[] { superb }, _valueHandler, _typeHandler, _asStatic);
}
}
// should not get here but...
throw new IllegalArgumentException("Internal error: Can not resolve sub-type for Class " + subclass.getName() + " to " + _class.getName());
}
use of com.fasterxml.jackson.databind.JavaType in project jackson-databind by FasterXML.
the class TypeBindings method findBoundType.
/*
/**********************************************************************
/* Accessors
/**********************************************************************
*/
/**
* Find type bound to specified name, if there is one; returns bound type if so, null if not.
*/
public JavaType findBoundType(String name) {
for (int i = 0, len = _names.length; i < len; ++i) {
if (name.equals(_names[i])) {
JavaType t = _types[i];
if (t instanceof ResolvedRecursiveType) {
ResolvedRecursiveType rrt = (ResolvedRecursiveType) t;
JavaType t2 = rrt.getSelfReferencedType();
if (t2 != null) {
t = t2;
} else {
/* 25-Feb-2016, tatu: Looks like a potential problem, but alas
* we have a test where this should NOT fail and things... seem
* to work. So be it.
*/
/*
throw new IllegalStateException(String.format
("Unresolved ResolvedRecursiveType for parameter '%s' (index #%d; erased type %s)",
name, i, t.getRawClass()));
*/
}
}
return t;
}
}
return null;
}
use of com.fasterxml.jackson.databind.JavaType in project retrofit by square.
the class JacksonConverterFactory method responseBodyConverter.
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
JavaType javaType = mapper.getTypeFactory().constructType(type);
ObjectReader reader = mapper.readerFor(javaType);
return new JacksonResponseBodyConverter<>(reader);
}
use of com.fasterxml.jackson.databind.JavaType in project retrofit by square.
the class JacksonConverterFactory method requestBodyConverter.
@Override
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
JavaType javaType = mapper.getTypeFactory().constructType(type);
ObjectWriter writer = mapper.writerFor(javaType);
return new JacksonRequestBodyConverter<>(writer);
}
Aggregations