Java Code Examples for com.fasterxml.jackson.databind.util.Converter#None

The following examples show how to use com.fasterxml.jackson.databind.util.Converter#None . 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: 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 2
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;
}