类com.fasterxml.jackson.databind.jsontype.TypeIdResolver源码实例Demo

下面列出了怎么用com.fasterxml.jackson.databind.jsontype.TypeIdResolver的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: milkman   文件: UnknownPluginHandler.java
@Override
public JavaType handleUnknownTypeId(DeserializationContext ctxt, JavaType baseType, String subTypeId,
		TypeIdResolver idResolver, String failureMsg) throws IOException {
	if (baseType.hasRawClass(RequestAspect.class)) {
		log.error("Unknown AspectType found: " + subTypeId + ".");
		return ReferenceType.construct(UnknownRequestAspect.class);
	}
	if (baseType.hasRawClass(OptionsObject.class)) {
		log.error("Unknown OptionsObject found: " + subTypeId + ".");
		return ReferenceType.construct(UnknownOptionsObject.class);
	}
	if (baseType.hasRawClass(RequestContainer.class)) {
		log.error("Unknown RequestContainer found: " + subTypeId + ".");
		return ReferenceType.construct(UnknownRequestContainer.class);
	}
	return null;
}
 
源代码2 项目: presto   文件: AbstractTypedJacksonModule.java
protected AbstractTypedJacksonModule(
        Class<T> baseClass,
        Function<T, String> nameResolver,
        Function<String, Class<? extends T>> classResolver)
{
    super(baseClass.getSimpleName() + "Module", Version.unknownVersion());

    TypeIdResolver typeResolver = new InternalTypeResolver<>(nameResolver, classResolver);

    addSerializer(baseClass, new InternalTypeSerializer<>(baseClass, typeResolver));
    addDeserializer(baseClass, new InternalTypeDeserializer<>(baseClass, typeResolver));
}
 
源代码3 项目: presto   文件: AbstractTypedJacksonModule.java
public InternalTypeDeserializer(Class<T> baseClass, TypeIdResolver typeIdResolver)
{
    super(baseClass);
    this.typeDeserializer = new AsPropertyTypeDeserializer(
            TypeFactory.defaultInstance().constructType(baseClass),
            typeIdResolver,
            TYPE_PROPERTY,
            false,
            null);
}
 
@Override
public TypeSerializer buildTypeSerializer(SerializationConfig config, JavaType baseType, Collection<NamedType> subtypes) {
    //Copied this code from parent class, StdTypeResolverBuilder with same method name
    TypeIdResolver idRes = this.idResolver(config, baseType, subtypes, true, false);
    // have to escape "." in the middle of the "odata.type" otherwise it will be serialized to "odata": { "type":"Value"} JSON
    String escapedString = this._typeProperty.replace(".", "\\.");
    return new AsPropertyTypeSerializer(idRes, (BeanProperty) null, escapedString);
}
 
源代码5 项目: lams   文件: MapperConfig.java
/**
 * Method that can be called to obtain an instance of <code>TypeIdResolver</code> of
 * specified type.
 */
public TypeIdResolver typeIdResolverInstance(Annotated annotated,
        Class<? extends TypeIdResolver> resolverClass)
{
    HandlerInstantiator hi = getHandlerInstantiator();
    if (hi != null) {
        TypeIdResolver builder = hi.typeIdResolverInstance(this, annotated, resolverClass);
        if (builder != null) {
            return builder;
        }
    }
    return (TypeIdResolver) ClassUtil.createInstance(resolverClass, canOverrideAccessModifiers());
}
 
源代码6 项目: lams   文件: AsPropertyTypeDeserializer.java
/**
 * @since 2.8
 */
public AsPropertyTypeDeserializer(JavaType bt, TypeIdResolver idRes,
        String typePropertyName, boolean typeIdVisible, JavaType defaultImpl,
        As inclusion)
{
    super(bt, idRes, typePropertyName, typeIdVisible, defaultImpl);
    _inclusion = inclusion;
}
 
源代码7 项目: lams   文件: TypeDeserializerBase.java
/**
 * @since 2.8
 */
protected TypeDeserializerBase(JavaType baseType, TypeIdResolver idRes,
        String typePropertyName, boolean typeIdVisible, JavaType defaultImpl)
{
    _baseType = baseType;
    _idResolver = idRes;
    _typePropertyName = ClassUtil.nonNullString(typePropertyName);
    _typeIdVisible = typeIdVisible;
    // defaults are fine, although shouldn't need much concurrency
    _deserializers = new ConcurrentHashMap<String, JsonDeserializer<Object>>(16, 0.75f, 2);
    _defaultImpl = defaultImpl;
    _property = null;
}
 
源代码8 项目: lams   文件: DeserializationContext.java
/**
 * Method that deserializers should call if they encounter a type id
 * (for polymorphic deserialization) that cannot be resolved to an
 * actual type; usually since there is no mapping defined.
 * Default implementation will try to call {@link DeserializationProblemHandler#handleUnknownTypeId}
 * on configured handlers, if any, to allow for recovery; if recovery does not
 * succeed, will throw exception constructed with {@link #invalidTypeIdException}.
 *
 * @param baseType Base type from which resolution starts
 * @param id Type id that could not be converted
 * @param extraDesc Additional problem description to add to default exception message,
 *    if resolution fails.
 *
 * @return {@link JavaType} that id resolves to
 *
 * @throws IOException To indicate unrecoverable problem, if resolution cannot
 *    be made to work
 *
 * @since 2.8
 */
public JavaType handleUnknownTypeId(JavaType baseType, String id,
        TypeIdResolver idResolver, String extraDesc) throws IOException
{
    LinkedNode<DeserializationProblemHandler> h = _config.getProblemHandlers();
    while (h != null) {
        // Can bail out if it's handled
        JavaType type = h.value().handleUnknownTypeId(this, baseType, id, idResolver, extraDesc);
        if (type != null) {
            if (type.hasRawClass(Void.class)) {
                return null;
            }
            // But ensure there's type compatibility
            if (type.isTypeOrSubTypeOf(baseType.getRawClass())) {
                return type;
            }
            throw invalidTypeIdException(baseType, id,
                    "problem handler tried to resolve into non-subtype: "+type);
        }
        h = h.next();
    }
    // 24-May-2016, tatu: Actually we may still not want to fail quite yet
    if (!isEnabled(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE)) {
        return null;
    }
    throw invalidTypeIdException(baseType, id, extraDesc);
}
 
源代码9 项目: lams   文件: DeserializationContext.java
/**
     * @since 2.9
     */
    public JavaType handleMissingTypeId(JavaType baseType,
            TypeIdResolver idResolver, String extraDesc) throws IOException
    {
        LinkedNode<DeserializationProblemHandler> h = _config.getProblemHandlers();
        while (h != null) {
            // Can bail out if it's handled
            JavaType type = h.value().handleMissingTypeId(this, baseType, idResolver, extraDesc);
            if (type != null) {
                if (type.hasRawClass(Void.class)) {
                    return null;
                }
                // But ensure there's type compatibility
                if (type.isTypeOrSubTypeOf(baseType.getRawClass())) {
                    return type;
                }
                throw invalidTypeIdException(baseType, null,
                        "problem handler tried to resolve into non-subtype: "+type);
            }
            h = h.next();
        }
        // 09-Mar-2017, tatu: We may want to consider yet another feature at some
        //    point to allow returning `null`... but that seems bit risky for now
//        if (!isEnabled(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE)) {
//            return null;
//        }
        throw missingTypeIdException(baseType, extraDesc);
    }
 
@Test
public void typeIdResolverInstanceReturnsNull() {

    // given
    VirtualProperty[] customProperties = new VirtualProperty[0];
    Log4j2Lookup valueResolver = new Log4j2Lookup(null);
    JacksonHandlerInstantiator handlerInstantiator = createTestHandlerInstantiator(customProperties, valueResolver);

    // when
    TypeIdResolver result = handlerInstantiator.typeIdResolverInstance(null, null, null);

    // then
    Assert.assertNull(result);

}
 
源代码11 项目: jackson-modules-base   文件: ProblemHandlerTest.java
@Override
public JavaType handleUnknownTypeId(DeserializationContext ctxt,
        JavaType baseType, String subTypeId, TypeIdResolver idResolver,
        String failureMsg)
    throws IOException
{
    return ctxt.constructType(raw);
}
 
源代码12 项目: jackson-modules-base   文件: ProblemHandlerTest.java
@Override
public JavaType handleMissingTypeId(DeserializationContext ctxt,
        JavaType baseType, TypeIdResolver idResolver,
        String failureMsg)
    throws IOException
{
    return ctxt.constructType(raw);
}
 
源代码13 项目: components   文件: NsTypeResolverBuilder.java
@Override
protected TypeIdResolver idResolver(MapperConfig<?> config, JavaType baseType,
                                    PolymorphicTypeValidator subtypeValidator, Collection<NamedType> subtypes,
                                    boolean forSer, boolean forDeser) {
    if (_idType == null) {
        throw new IllegalStateException("Can not build, 'init()' not yet called");
    }

    return new NsTypeIdResolver(baseType, config.getTypeFactory(), basicMetaData);
}
 
源代码14 项目: presto   文件: AbstractTypedJacksonModule.java
public InternalTypeSerializer(Class<T> baseClass, TypeIdResolver typeIdResolver)
{
    super(baseClass);
    this.typeSerializer = new AsPropertyTypeSerializer(typeIdResolver, null, TYPE_PROPERTY);
}
 
@Override
public TypeIdResolver typeIdResolverInstance(MapperConfig<?> config, Annotated annotated, Class<?> implClass) {
	return (TypeIdResolver) this.beanFactory.createBean(implClass);
}
 
@Override
public TypeIdResolver typeIdResolverInstance(MapperConfig<?> config, Annotated annotated, Class<?> implClass) {
	return (TypeIdResolver) this.beanFactory.createBean(implClass);
}
 
源代码17 项目: lams   文件: SpringHandlerInstantiator.java
@Override
public TypeIdResolver typeIdResolverInstance(MapperConfig<?> config, Annotated annotated, Class<?> implClass) {
	return (TypeIdResolver) this.beanFactory.createBean(implClass);
}
 
源代码18 项目: lams   文件: AsPropertyTypeDeserializer.java
/**
 * @since 2.8
 */
public AsPropertyTypeDeserializer(JavaType bt, TypeIdResolver idRes,
        String typePropertyName, boolean typeIdVisible, JavaType defaultImpl)
{
    this(bt, idRes, typePropertyName, typeIdVisible, defaultImpl, As.PROPERTY);
}
 
源代码19 项目: lams   文件: AsArrayTypeDeserializer.java
/**
 * @since 2.8
 */
public AsArrayTypeDeserializer(JavaType bt, TypeIdResolver idRes,
        String typePropertyName, boolean typeIdVisible, JavaType defaultImpl)
{
    super(bt, idRes, typePropertyName, typeIdVisible, defaultImpl);
}
 
源代码20 项目: lams   文件: TypeSerializerBase.java
protected TypeSerializerBase(TypeIdResolver idRes, BeanProperty property)
{
    _idResolver = idRes;
    _property = property;
}
 
源代码21 项目: lams   文件: TypeSerializerBase.java
@Override
public TypeIdResolver getTypeIdResolver() { return _idResolver; }
 
源代码22 项目: lams   文件: AsWrapperTypeDeserializer.java
/**
 * @since 2.8
 */
public AsWrapperTypeDeserializer(JavaType bt, TypeIdResolver idRes,
        String typePropertyName, boolean typeIdVisible, JavaType defaultImpl)
{
    super(bt, idRes, typePropertyName, typeIdVisible, defaultImpl);
}
 
源代码23 项目: lams   文件: AsWrapperTypeSerializer.java
public AsWrapperTypeSerializer(TypeIdResolver idRes, BeanProperty property) {
    super(idRes, property);
}
 
源代码24 项目: lams   文件: AsPropertyTypeSerializer.java
public AsPropertyTypeSerializer(TypeIdResolver idRes, BeanProperty property, String propName)
{
    super(idRes, property);
    _typePropertyName = propName;
}
 
源代码25 项目: lams   文件: AsExistingPropertyTypeSerializer.java
public AsExistingPropertyTypeSerializer(TypeIdResolver idRes,
        BeanProperty property, String propName)
{
    super(idRes, property, propName);
}
 
源代码26 项目: lams   文件: AsArrayTypeSerializer.java
public AsArrayTypeSerializer(TypeIdResolver idRes, BeanProperty property) {
    super(idRes, property);
}
 
源代码27 项目: lams   文件: TypeDeserializerBase.java
@Override    
public TypeIdResolver getTypeIdResolver() { return _idResolver; }
 
源代码28 项目: lams   文件: AsExternalTypeDeserializer.java
/**
 * @since 2.8
 */
public AsExternalTypeDeserializer(JavaType bt, TypeIdResolver idRes,
        String typePropertyName, boolean typeIdVisible, JavaType defaultImpl)
{
    super(bt, idRes, typePropertyName, typeIdVisible, defaultImpl);
}
 
源代码29 项目: lams   文件: AsExternalTypeSerializer.java
public AsExternalTypeSerializer(TypeIdResolver idRes, BeanProperty property, String propName) {
    super(idRes, property);
    _typePropertyName = propName;
}
 
源代码30 项目: lams   文件: JsonValueSerializer.java
@Override
public TypeIdResolver getTypeIdResolver() {
    return _typeSerializer.getTypeIdResolver();
}
 
 类方法
 同包方法