use of com.fasterxml.jackson.databind.AnnotationIntrospector in project hadoop by apache.
the class YarnJacksonJaxbJsonProvider method configObjectMapper.
public static void configObjectMapper(ObjectMapper mapper) {
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
mapper.setAnnotationIntrospector(introspector);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
use of com.fasterxml.jackson.databind.AnnotationIntrospector in project jersey by jersey.
the class FilteringJacksonJaxbJsonProvider method _configForWriting.
@Override
protected JsonEndpointConfig _configForWriting(final ObjectMapper mapper, final Annotation[] annotations, final Class<?> defaultView) {
final AnnotationIntrospector customIntrospector = mapper.getSerializationConfig().getAnnotationIntrospector();
// Set the custom (user) introspector to be the primary one.
final ObjectMapper filteringMapper = mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(customIntrospector, new JacksonAnnotationIntrospector() {
@Override
public Object findFilterId(final Annotated a) {
final Object filterId = super.findFilterId(a);
if (filterId != null) {
return filterId;
}
if (a instanceof AnnotatedMethod) {
final Method method = ((AnnotatedMethod) a).getAnnotated();
// Interested only in getters - trying to obtain "field" name from them.
if (ReflectionHelper.isGetter(method)) {
return ReflectionHelper.getPropertyName(method);
}
}
if (a instanceof AnnotatedField || a instanceof AnnotatedClass) {
return a.getName();
}
return null;
}
}));
return super._configForWriting(filteringMapper, annotations, defaultView);
}
use of com.fasterxml.jackson.databind.AnnotationIntrospector in project jersey by jersey.
the class MyObjectMapperProvider method createJaxbJacksonAnnotationIntrospector.
private static AnnotationIntrospector createJaxbJacksonAnnotationIntrospector() {
final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
final AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
return AnnotationIntrospector.pair(jacksonIntrospector, jaxbIntrospector);
}
use of com.fasterxml.jackson.databind.AnnotationIntrospector in project jackson-databind by FasterXML.
the class StdSubtypeResolver method collectAndResolveSubtypesByTypeId.
/*
/**********************************************************
/* Resolution by class (deserialization)
/**********************************************************
*/
@Override
public Collection<NamedType> collectAndResolveSubtypesByTypeId(MapperConfig<?> config, AnnotatedMember property, JavaType baseType) {
final AnnotationIntrospector ai = config.getAnnotationIntrospector();
Class<?> rawBase = (baseType == null) ? property.getRawType() : baseType.getRawClass();
// Need to keep track of classes that have been handled already
Set<Class<?>> typesHandled = new HashSet<Class<?>>();
Map<String, NamedType> byName = new LinkedHashMap<String, NamedType>();
// start with lowest-precedence, which is from type hierarchy
NamedType rootType = new NamedType(rawBase, null);
AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(rawBase, config);
_collectAndResolveByTypeId(ac, rootType, config, typesHandled, byName);
// then with definitions from property
Collection<NamedType> st = ai.findSubtypes(property);
if (st != null) {
for (NamedType nt : st) {
ac = AnnotatedClass.constructWithoutSuperTypes(nt.getType(), config);
_collectAndResolveByTypeId(ac, nt, config, typesHandled, byName);
}
}
// and finally explicit type registrations (highest precedence)
if (_registeredSubtypes != null) {
for (NamedType subtype : _registeredSubtypes) {
// is it a subtype of root type?
if (rawBase.isAssignableFrom(subtype.getType())) {
// yes
AnnotatedClass curr = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), config);
_collectAndResolveByTypeId(curr, subtype, config, typesHandled, byName);
}
}
}
return _combineNamedAndUnnamed(typesHandled, byName);
}
use of com.fasterxml.jackson.databind.AnnotationIntrospector in project jackson-databind by FasterXML.
the class StdSubtypeResolver method _collectAndResolveByTypeId.
/**
* Method called to find subtypes for a specific type (class), using
* type id as the unique key (in case of conflicts).
*/
protected void _collectAndResolveByTypeId(AnnotatedClass annotatedType, NamedType namedType, MapperConfig<?> config, Set<Class<?>> typesHandled, Map<String, NamedType> byName) {
final AnnotationIntrospector ai = config.getAnnotationIntrospector();
if (!namedType.hasName()) {
String name = ai.findTypeName(annotatedType);
if (name != null) {
namedType = new NamedType(namedType.getType(), name);
}
}
if (namedType.hasName()) {
byName.put(namedType.getName(), namedType);
}
// only check subtypes if this type hadn't yet been handled
if (typesHandled.add(namedType.getType())) {
Collection<NamedType> st = ai.findSubtypes(annotatedType);
if (st != null && !st.isEmpty()) {
for (NamedType subtype : st) {
AnnotatedClass subtypeClass = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), config);
_collectAndResolveByTypeId(subtypeClass, subtype, config, typesHandled, byName);
}
}
}
}
Aggregations