下面列出了怎么用com.fasterxml.jackson.databind.DatabindContext的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
protected JavaType _typeFromId(String id, DatabindContext ctxt) throws IOException
{
if (id.startsWith(".")) {
StringBuilder sb = new StringBuilder(id.length() + _basePackageName.length());
if (_basePackageName.length() == 0) {
// no package; must remove leading '.' from id
sb.append(id.substring(1));
} else {
// otherwise just concatenate package, with leading-dot-partial name
sb.append(_basePackageName).append(id);
}
id = sb.toString();
}
return super._typeFromId(id, ctxt);
}
@Override
public JavaType typeFromId(DatabindContext context, String id) throws IOException {
Class<?> type = idToClassMapping.get(id);
if (type == null) {
synchronized (TypeAliasIdResolver.class) {
type = idToClassMapping.get(id);
if (type == null) {
int commaPos = id.indexOf(",");
if (commaPos > 0) {
String exactId = id.substring(0, commaPos).trim();
type = idToClassMapping.get(exactId);
if (type != null) {
idToClassMapping.put(id, type);
}
}
}
}
}
if (type != null) {
return context.constructType(type);
} else {
throw new IllegalArgumentException(String.format("Unknown type for id %s", id));
}
}
@Override
public JavaType typeFromId(DatabindContext databindContext, String s) {
Type fieldType = Schema.Type.valueOf(s);
JavaType javaType;
switch (fieldType) {
case NESTED:
javaType = TypeFactory.defaultInstance().constructType(NestedField.class);
break;
case ARRAY:
javaType = TypeFactory.defaultInstance().constructType(ArrayField.class);
break;
default:
javaType = TypeFactory.defaultInstance().constructType(Field.class);
}
return javaType;
}
@Override
public JavaType typeFromId(DatabindContext context, String id)
{
requireNonNull(id, "id is null");
Class<?> typeClass = classResolver.apply(id);
checkArgument(typeClass != null, "Unknown type ID: %s", id);
return context.getTypeFactory().constructType(typeClass);
}
@Override
public JavaType typeFromId(DatabindContext context, String id) {
Class<?> subType = null;
if (id.endsWith("[]")) {
subType = ArrayParameter.class;
} else if (id.startsWith("byte") || id.equals("string") || id.equals("address")) {
subType = StringParameter.class;
} else if (id.startsWith("uint") || id.startsWith("int") || id.startsWith("bool")) {
subType = NumberParameter.class;
}
return context.constructSpecializedType(superType, subType);
}
@Override
public JavaType typeFromId(DatabindContext context, String id) {
Class<?> result = typeMap.get(id);
if (result == null) {
throw new IllegalStateException(
"There is no type " + id + " for " + baseType.getTypeName() + ". Try: "
+ getDescForKnownTypeIds());
}
return TypeFactory.defaultInstance().constructSpecializedType(baseType, result);
}
@Override
public JavaType typeFromId(DatabindContext context, String id) throws IOException {
Class t = null;
if (id.equals("integer")) {
t = DataEntry.LongEntry.class;
} else if (id.equals("boolean")) {
t = DataEntry.BooleanEntry.class;
} else if (id.equals("binary")) {
t = DataEntry.BinaryEntry.class;
} else if (id.equals("string")) {
t = DataEntry.StringEntry.class;
}
return context.constructType(t);
}
@Override
public JavaType typeFromId(DatabindContext context, String id) throws IOException {
// 22-Dec-2015, tatu: Must be overridden by sub-classes, so let's throw
// an exception if not
throw new IllegalStateException("Sub-class "+getClass().getName()+" MUST implement "
+"`typeFromId(DatabindContext,String)");
}
@Override
public JavaType typeFromId(DatabindContext context, String id) {
JavaType type = nameToType.get(id.toLowerCase());
if (type == null) {
throw new NullPointerException(
format("no subtype of %s found for enum value %s. existing mappings:\n%s",
baseType, id, description));
}
return type;
}
@Override
public JavaType typeFromId(final DatabindContext context, final String id) {
switch (id) {
case PasswordCredential.TYPE:
return context.constructSpecializedType(this.baseType, PasswordCredential.class);
case PskCredential.TYPE:
return context.constructSpecializedType(this.baseType, PskCredential.class);
case X509CertificateCredential.TYPE:
return context.constructSpecializedType(this.baseType, X509CertificateCredential.class);
default:
return context.constructSpecializedType(this.baseType, GenericCredential.class);
}
}
@Override
public JavaType typeFromId(DatabindContext context, String id) throws IOException {
try {
Class<?> type = Class.forName(id);
return context.constructType(type);
} catch (ClassNotFoundException e) {
if(!(context instanceof DeserializationContext)) {
throw new RuntimeException(e);
}
//see magic from ClassNameIdResolver._typeFromId()
return ((DeserializationContext) context).handleUnknownTypeId(_baseType, id, this,
"Class '" + id + "' not found.");
}
}
@SuppressWarnings("unchecked")
@Override
public JavaType typeFromId(final DatabindContext context,
final String id) {
return context.constructType(beanTypeResolver.resolveTypeClass(id,
(Class<ConfiguredBean>) baseType.getRawClass()));
}
@Override
protected JavaType _typeFromId(String typeName, DatabindContext ctxt) {
Class result = rmInfoLookup.getClass(typeName);
if(result == null) {
//AOM class?
result = aomInfoLookup.getClass(typeName);
}
if(result != null) {
TypeFactory typeFactory = (ctxt == null) ? _typeFactory : ctxt.getTypeFactory();
return typeFactory.constructSpecializedType(_baseType, result);
}
return super._typeFromId(typeName, ctxt);
}
@Override
public JavaType typeFromId(DatabindContext context, String id) {
Class klass = getKnownTypes().get(id);
if (klass == null) {
return null;
}
JavaType[] typeArgs = klass.equals(Event.class) ?
new JavaType[]{context.getTypeFactory().constructSimpleType(Model.class, new JavaType[]{})} :
new JavaType[]{};
return context.getTypeFactory().constructSimpleType(klass, typeArgs);
}
@Override
public JavaType typeFromId(DatabindContext context, String id) {
Class<?> clazz = basicMetaData.getTypeClass(id);
if (clazz == null) {
return null;
}
JavaType javaType = SimpleType.construct(clazz);
return javaType;
}
@Override
public JavaType typeFromId(DatabindContext context, String id) {
try {
return SimpleType.constructUnsafe(Class.forName(getClass().getPackage().getName() + "." + id.substring(0, 1).toUpperCase() + id.substring(1)));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@Override
protected JavaType _typeFromId(final String id, final DatabindContext ctxt) throws IOException {
Class<?> clazz = idToClass.get(id);
if (clazz != null) {
return _typeFactory.constructSpecializedType(_baseType, clazz);
}
return super._typeFromId(id, ctxt);
}
@Override
public JavaType typeFromId(DatabindContext context, String id) {
if ("set".equals(id)) {
return context.getTypeFactory().constructCollectionType(OvsdbSet.class, Object.class);
} else if ("uuid".equals(id) || "named-uuid".equals(id)) {
return context.constructType(UUID.class);
}
return null;
}
@Override
public JavaType typeFromId(DatabindContext context, String id) {
Class<?> subType = null;
switch (id) {
case "bean1":
subType = FirstBean.class;
break;
case "bean2":
subType = LastBean.class;
}
return context.constructSpecializedType(superType, subType);
}
@Override
public JavaType typeFromId(DatabindContext context, String id) throws IOException {
return TypeFactory.defaultInstance().constructSpecializedType(baseType, TYPES.get(id));
}
@Override
public JavaType typeFromId(DatabindContext context, String id) {
return null;
}
@Override
public JavaType typeFromId(DatabindContext context, String id) {
return null;
}
@Override
public JavaType typeFromId(DatabindContext context, String id) {
return _typeFromId(id);
}
public static final boolean isNumberAsString(DatabindContext context) {
Object attr = context.getAttribute(DataJsonOutput.DREMIO_JOB_DATA_NUMBERS_AS_STRINGS_ATTRIBUTE);
return attr instanceof Boolean && ((Boolean)attr).booleanValue();
}
public TestDataJsonOutput(final Object inputValue, final boolean expectedValue) {
this.context = Mockito.mock(DatabindContext.class);
this.inputValue = inputValue;
this.expectedValue = expectedValue;
}
public JavaType typeFromId(DatabindContext context, String id) {
return null;
}
@Override
public Validity validateBaseType(DatabindContext ctxt, JavaType baseType) {
return Validity.ALLOWED;
}
@Override
public Validity validateBaseType(DatabindContext ctxt, JavaType baseType) {
return Validity.ALLOWED;
}
@Override
public Validity validateBaseType(DatabindContext ctxt, JavaType baseType) {
return Validity.INDETERMINATE;
}
@Override
public Validity validateSubClassName(DatabindContext ctxt,
JavaType baseType, String subClassName) {
return Validity.ALLOWED;
}