use of com.fasterxml.jackson.databind.util.Converter in project jackson-databind by FasterXML.
the class DatabindContext method converterInstance.
/**
* 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;
}
use of com.fasterxml.jackson.databind.util.Converter in project jackson-databind by FasterXML.
the class BasicBeanDescription method _createConverter.
/*
/**********************************************************
/* Helper methods, other
/**********************************************************
*/
@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;
}
Aggregations