use of com.fasterxml.jackson.databind.cfg.HandlerInstantiator in project jackson-databind by FasterXML.
the class POJOPropertiesCollector method _findNamingStrategy.
private PropertyNamingStrategy _findNamingStrategy() {
Object namingDef = (_annotationIntrospector == null) ? null : _annotationIntrospector.findNamingStrategy(_classDef);
if (namingDef == null) {
return _config.getPropertyNamingStrategy();
}
if (namingDef instanceof PropertyNamingStrategy) {
return (PropertyNamingStrategy) namingDef;
}
/* Alas, there's no way to force return type of "either class
* X or Y" -- need to throw an exception after the fact
*/
if (!(namingDef instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector returned PropertyNamingStrategy definition of type " + namingDef.getClass().getName() + "; expected type PropertyNamingStrategy or Class<PropertyNamingStrategy> instead");
}
Class<?> namingClass = (Class<?>) namingDef;
// 09-Nov-2015, tatu: Need to consider pseudo-value of STD, which means "use default"
if (namingClass == PropertyNamingStrategy.class) {
return null;
}
if (!PropertyNamingStrategy.class.isAssignableFrom(namingClass)) {
throw new IllegalStateException("AnnotationIntrospector returned Class " + namingClass.getName() + "; expected Class<PropertyNamingStrategy>");
}
HandlerInstantiator hi = _config.getHandlerInstantiator();
if (hi != null) {
PropertyNamingStrategy pns = hi.namingStrategyInstance(_config, _classDef, namingClass);
if (pns != null) {
return pns;
}
}
return (PropertyNamingStrategy) ClassUtil.createInstance(namingClass, _config.canOverrideAccessModifiers());
}
use of com.fasterxml.jackson.databind.cfg.HandlerInstantiator 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;
}
use of com.fasterxml.jackson.databind.cfg.HandlerInstantiator in project jackson-databind by FasterXML.
the class DefaultDeserializationContext method deserializerInstance.
/*
/**********************************************************
/* Abstract methods impls, other factory methods
/**********************************************************
*/
@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;
}
use of com.fasterxml.jackson.databind.cfg.HandlerInstantiator in project jackson-databind by FasterXML.
the class DatabindContext method objectIdGeneratorInstance.
/*
/**********************************************************
/* Helper object construction
/**********************************************************
*/
public ObjectIdGenerator<?> objectIdGeneratorInstance(Annotated annotated, ObjectIdInfo objectIdInfo) throws JsonMappingException {
Class<?> implClass = objectIdInfo.getGeneratorType();
final MapperConfig<?> config = getConfig();
HandlerInstantiator hi = config.getHandlerInstantiator();
ObjectIdGenerator<?> gen = (hi == null) ? null : hi.objectIdGeneratorInstance(config, annotated, implClass);
if (gen == null) {
gen = (ObjectIdGenerator<?>) ClassUtil.createInstance(implClass, config.canOverrideAccessModifiers());
}
return gen.forScope(objectIdInfo.getScope());
}
use of com.fasterxml.jackson.databind.cfg.HandlerInstantiator in project jackson-databind by FasterXML.
the class DefaultSerializerProvider method serializerInstance.
/*
/**********************************************************
/* Abstract method impls, factory methods
/**********************************************************
*/
@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 {
// 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);
}
Aggregations