com.fasterxml.jackson.databind.DatabindContext Java Examples

The following examples show how to use com.fasterxml.jackson.databind.DatabindContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MinimalClassNameIdResolver.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: TypeAliasIdResolver.java    From caravan with Apache License 2.0 6 votes vote down vote up
@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));
	}
}
 
Example #3
Source File: Schema.java    From registry with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #4
Source File: AbstractTypedJacksonModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #5
Source File: TypeIdResolverStructure.java    From tutorials with MIT License 5 votes vote down vote up
@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);
}
 
Example #6
Source File: OvsdbTypesIdResolver.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example #7
Source File: ClassAliasIdResolver.java    From simple-spring-memcached with MIT License 5 votes vote down vote up
@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);
}
 
Example #8
Source File: NodeTypeResolver.java    From depgraph-maven-plugin with Apache License 2.0 5 votes vote down vote up
@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);
  }
}
 
Example #9
Source File: NsTypeIdResolver.java    From components with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #10
Source File: ModelTypeResolver.java    From omise-java with MIT License 5 votes vote down vote up
@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);
}
 
Example #11
Source File: OpenEHRTypeNaming.java    From archie with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #12
Source File: ConfiguredBean.java    From logsniffer with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public JavaType typeFromId(final DatabindContext context,
		final String id) {
	return context.constructType(beanTypeResolver.resolveTypeClass(id,
			(Class<ConfiguredBean>) baseType.getRawClass()));
}
 
Example #13
Source File: CustomTypeIdResolver.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
@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.");
    }
}
 
Example #14
Source File: CredentialTypeResolver.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #15
Source File: EnumTypeIdResolver.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #16
Source File: TypeIdResolverBase.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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)");
}
 
Example #17
Source File: ParameterTypeIdResolver.java    From eventeum with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #18
Source File: CPSTypeIdResolver.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #19
Source File: DataEntryTypeResolver.java    From WavesJ with MIT License 5 votes vote down vote up
@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);
}
 
Example #20
Source File: TypeNameIdResolver.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public JavaType typeFromId(DatabindContext context, String id) {
    return _typeFromId(id);
}
 
Example #21
Source File: UserTypeIdResolver.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
@Override
public JavaType typeFromId(DatabindContext context, String id) {
  return JAVA_TYPE;
}
 
Example #22
Source File: LoginTypeIdResolver.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
@Override
public JavaType typeFromId(DatabindContext context, String id) {
  return JAVA_TYPE;
}
 
Example #23
Source File: DestinationTypeIdResolver.java    From data-highway with Apache License 2.0 4 votes vote down vote up
@Override
public JavaType typeFromId(DatabindContext context, String id) throws IOException {
  return TypeFactory.defaultInstance().constructSpecializedType(baseType, TYPES.get(id));
}
 
Example #24
Source File: SpringHandlerInstantiatorTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public JavaType typeFromId(DatabindContext context, String id) {
	return null;
}
 
Example #25
Source File: SpringHandlerInstantiatorTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public JavaType typeFromId(DatabindContext context, String id) {
	return null;
}
 
Example #26
Source File: OpenEHRTypeNaming.java    From archie with Apache License 2.0 4 votes vote down vote up
@Override
public JavaType typeFromId(DatabindContext context, String id) {
    return _typeFromId(id, context);
}
 
Example #27
Source File: TestDataJsonOutput.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public TestDataJsonOutput(final Object inputValue, final boolean expectedValue) {
   this.context = Mockito.mock(DatabindContext.class);
   this.inputValue = inputValue;
   this.expectedValue = expectedValue;
}
 
Example #28
Source File: NoCheckSubTypeValidator.java    From jackson-modules-base with Apache License 2.0 4 votes vote down vote up
@Override
public Validity validateSubType(DatabindContext ctxt, JavaType baseType,
        JavaType subType) {
    return Validity.ALLOWED;
}
 
Example #29
Source File: NoCheckSubTypeValidator.java    From jackson-modules-base with Apache License 2.0 4 votes vote down vote up
@Override
public Validity validateSubClassName(DatabindContext ctxt,
        JavaType baseType, String subClassName) {
    return Validity.ALLOWED;
}
 
Example #30
Source File: NoCheckSubTypeValidator.java    From jackson-modules-base with Apache License 2.0 4 votes vote down vote up
@Override
public Validity validateBaseType(DatabindContext ctxt, JavaType baseType) {
    return Validity.INDETERMINATE;
}