Java Code Examples for com.fasterxml.jackson.databind.util.ClassUtil#isBogusClass()

The following examples show how to use com.fasterxml.jackson.databind.util.ClassUtil#isBogusClass() . 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: TypeDeserializerBase.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected final JsonDeserializer<Object> _findDefaultImplDeserializer(DeserializationContext ctxt) throws IOException
{
    /* 06-Feb-2013, tatu: As per [databind#148], consider default implementation value of
     *   {@link java.lang.Void} to mean "serialize as null"; as well as DeserializationFeature
     *   to do swift mapping to null
     */
    if (_defaultImpl == null) {
        if (!ctxt.isEnabled(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE)) {
            return NullifyingDeserializer.instance;
        }
        return null;
    }
    Class<?> raw = _defaultImpl.getRawClass();
    if (ClassUtil.isBogusClass(raw)) {
        return NullifyingDeserializer.instance;
    }
    
    synchronized (_defaultImpl) {
        if (_defaultImplDeserializer == null) {
            _defaultImplDeserializer = ctxt.findContextualValueDeserializer(
                    _defaultImpl, _property);
        }
        return _defaultImplDeserializer;
    }
}
 
Example 2
Source File: DefaultSerializerProvider.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public JsonSerializer<Object> serializerInstance(Annotated annotated, Object serDef)
        throws JsonMappingException
{
    if (serDef == null) {
        return null;
    }
    JsonSerializer<?> ser;
    
    if (serDef instanceof JsonSerializer) {
        ser = (JsonSerializer<?>) serDef;
    } else {
        // Alas, there's no way to force return type of "either class
        // X or Y" -- need to throw an exception after the fact
        if (!(serDef instanceof Class)) {
            reportBadDefinition(annotated.getType(),
                    "AnnotationIntrospector returned serializer definition of type "
                    +serDef.getClass().getName()+"; expected type JsonSerializer or Class<JsonSerializer> instead");
        }
        Class<?> serClass = (Class<?>)serDef;
        // there are some known "no class" markers to consider too:
        if (serClass == JsonSerializer.None.class || ClassUtil.isBogusClass(serClass)) {
            return null;
        }
        if (!JsonSerializer.class.isAssignableFrom(serClass)) {
            reportBadDefinition(annotated.getType(),
                    "AnnotationIntrospector returned Class "
                    +serClass.getName()+"; expected Class<JsonSerializer>");
        }
        HandlerInstantiator hi = _config.getHandlerInstantiator();
        ser = (hi == null) ? null : hi.serializerInstance(_config, annotated, serClass);
        if (ser == null) {
            ser = (JsonSerializer<?>) ClassUtil.createInstance(serClass,
                    _config.canOverrideAccessModifiers());
        }
    }
    return (JsonSerializer<Object>) _handleResolvable(ser);
}
 
Example 3
Source File: DatabindContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method to use to construct a {@link Converter}, given a definition
 * that may be either actual converter instance, or Class for instantiating one.
 * 
 * @since 2.2
 */
@SuppressWarnings("unchecked")
public Converter<Object,Object> converterInstance(Annotated annotated,
        Object converterDef)
    throws JsonMappingException
{
    if (converterDef == null) {
        return null;
    }
    if (converterDef instanceof Converter<?,?>) {
        return (Converter<Object,Object>) converterDef;
    }
    if (!(converterDef instanceof Class)) {
        throw new IllegalStateException("AnnotationIntrospector returned Converter definition of type "
                +converterDef.getClass().getName()+"; expected type Converter or Class<Converter> instead");
    }
    Class<?> converterClass = (Class<?>)converterDef;
    // there are some known "no class" markers to consider too:
    if (converterClass == Converter.None.class || ClassUtil.isBogusClass(converterClass)) {
        return null;
    }
    if (!Converter.class.isAssignableFrom(converterClass)) {
        throw new IllegalStateException("AnnotationIntrospector returned Class "
                +converterClass.getName()+"; expected Class<Converter>");
    }
    final MapperConfig<?> config = getConfig();
    HandlerInstantiator hi = config.getHandlerInstantiator();
    Converter<?,?> conv = (hi == null) ? null : hi.converterInstance(config, annotated, converterClass);
    if (conv == null) {
        conv = (Converter<?,?>) ClassUtil.createInstance(converterClass,
                config.canOverrideAccessModifiers());
    }
    return (Converter<Object,Object>) conv;
}
 
Example 4
Source File: BasicBeanDescription.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected Converter<Object,Object> _createConverter(Object converterDef)
{
    if (converterDef == null) {
        return null;
    }
    if (converterDef instanceof Converter<?,?>) {
        return (Converter<Object,Object>) converterDef;
    }
    if (!(converterDef instanceof Class)) {
        throw new IllegalStateException("AnnotationIntrospector returned Converter definition of type "
                +converterDef.getClass().getName()+"; expected type Converter or Class<Converter> instead");
    }
    Class<?> converterClass = (Class<?>)converterDef;
    // there are some known "no class" markers to consider too:
    if (converterClass == Converter.None.class || ClassUtil.isBogusClass(converterClass)) {
        return null;
    }
    if (!Converter.class.isAssignableFrom(converterClass)) {
        throw new IllegalStateException("AnnotationIntrospector returned Class "
                +converterClass.getName()+"; expected Class<Converter>");
    }
    HandlerInstantiator hi = _config.getHandlerInstantiator();
    Converter<?,?> conv = (hi == null) ? null : hi.converterInstance(_config, _classInfo, converterClass);
    if (conv == null) {
        conv = (Converter<?,?>) ClassUtil.createInstance(converterClass,
                _config.canOverrideAccessModifiers());
    }
    return (Converter<Object,Object>) conv;
}
 
Example 5
Source File: AnnotationIntrospectorPair.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected boolean _isExplicitClassOrOb(Object maybeCls, Class<?> implicit) {
    if ((maybeCls == null) || (maybeCls == implicit)) {
        return false;
    }
    if (maybeCls instanceof Class<?>) {
        return !ClassUtil.isBogusClass((Class<?>) maybeCls);
    }
    return true;
}
 
Example 6
Source File: AnnotationIntrospectorPair.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected Object _explicitClassOrOb(Object maybeCls, Class<?> implicit) {
    if ((maybeCls == null) || (maybeCls == implicit)) {
        return null;
    }
    if ((maybeCls instanceof Class<?>) && ClassUtil.isBogusClass((Class<?>) maybeCls)) {
        return null;
    }
    return maybeCls;
}
 
Example 7
Source File: DefaultDeserializationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public JsonDeserializer<Object> deserializerInstance(Annotated ann, Object deserDef)
    throws JsonMappingException
{
    if (deserDef == null) {
        return null;
    }
    JsonDeserializer<?> deser;
    
    if (deserDef instanceof JsonDeserializer) {
        deser = (JsonDeserializer<?>) deserDef;
    } else {
        /* Alas, there's no way to force return type of "either class
         * X or Y" -- need to throw an exception after the fact
         */
        if (!(deserDef instanceof Class)) {
            throw new IllegalStateException("AnnotationIntrospector returned deserializer definition of type "+deserDef.getClass().getName()+"; expected type JsonDeserializer or Class<JsonDeserializer> instead");
        }
        Class<?> deserClass = (Class<?>)deserDef;
        // there are some known "no class" markers to consider too:
        if (deserClass == JsonDeserializer.None.class || ClassUtil.isBogusClass(deserClass)) {
            return null;
        }
        if (!JsonDeserializer.class.isAssignableFrom(deserClass)) {
            throw new IllegalStateException("AnnotationIntrospector returned Class "+deserClass.getName()+"; expected Class<JsonDeserializer>");
        }
        HandlerInstantiator hi = _config.getHandlerInstantiator();
        deser = (hi == null) ? null : hi.deserializerInstance(_config, ann, deserClass);
        if (deser == null) {
            deser = (JsonDeserializer<?>) ClassUtil.createInstance(deserClass,
                    _config.canOverrideAccessModifiers());
        }
    }
    // First: need to resolve
    if (deser instanceof ResolvableDeserializer) {
        ((ResolvableDeserializer) deser).resolve(this);
    }
    return (JsonDeserializer<Object>) deser;
}
 
Example 8
Source File: DefaultDeserializationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final KeyDeserializer keyDeserializerInstance(Annotated ann, Object deserDef)
    throws JsonMappingException
{
    if (deserDef == null) {
        return null;
    }

    KeyDeserializer deser;
    
    if (deserDef instanceof KeyDeserializer) {
        deser = (KeyDeserializer) deserDef;
    } else {
        if (!(deserDef instanceof Class)) {
            throw new IllegalStateException("AnnotationIntrospector returned key deserializer definition of type "
                    +deserDef.getClass().getName()
                    +"; expected type KeyDeserializer or Class<KeyDeserializer> instead");
        }
        Class<?> deserClass = (Class<?>)deserDef;
        // there are some known "no class" markers to consider too:
        if (deserClass == KeyDeserializer.None.class || ClassUtil.isBogusClass(deserClass)) {
            return null;
        }
        if (!KeyDeserializer.class.isAssignableFrom(deserClass)) {
            throw new IllegalStateException("AnnotationIntrospector returned Class "+deserClass.getName()
                    +"; expected Class<KeyDeserializer>");
        }
        HandlerInstantiator hi = _config.getHandlerInstantiator();
        deser = (hi == null) ? null : hi.keyDeserializerInstance(_config, ann, deserClass);
        if (deser == null) {
            deser = (KeyDeserializer) ClassUtil.createInstance(deserClass,
                    _config.canOverrideAccessModifiers());
        }
    }
    // First: need to resolve
    if (deser instanceof ResolvableDeserializer) {
        ((ResolvableDeserializer) deser).resolve(this);
    }
    return deser;
}
 
Example 9
Source File: DeserializerCache.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private Class<?> _verifyAsClass(Object src, String methodName, Class<?> noneClass)
{
    if (src == null) {
        return null;
    }
    if (!(src instanceof Class)) {
        throw new IllegalStateException("AnnotationIntrospector."+methodName+"() returned value of type "+src.getClass().getName()+": expected type JsonSerializer or Class<JsonSerializer> instead");
    }
    Class<?> cls = (Class<?>) src;
    if (cls == noneClass || ClassUtil.isBogusClass(cls)) {
        return null;
    }
    return cls;
}