use of com.fasterxml.jackson.databind.introspect.AnnotatedClass 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.introspect.AnnotatedClass in project jackson-databind by FasterXML.
the class TestJacksonAnnotationIntrospector method testJsonTypeResolver.
public void testJsonTypeResolver() throws Exception {
ObjectMapper mapper = new ObjectMapper();
JacksonAnnotationIntrospector ai = new JacksonAnnotationIntrospector();
AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(TypeResolverBean.class, mapper.getSerializationConfig());
JavaType baseType = TypeFactory.defaultInstance().constructType(TypeResolverBean.class);
TypeResolverBuilder<?> rb = ai.findTypeResolver(mapper.getDeserializationConfig(), ac, baseType);
assertNotNull(rb);
assertSame(DummyBuilder.class, rb.getClass());
}
use of com.fasterxml.jackson.databind.introspect.AnnotatedClass in project jackson-databind by FasterXML.
the class DeprecatedConstructType1456Test method testGenericParameterViaClass.
// and this is how new code should resolve types if at all possible
public void testGenericParameterViaClass() throws Exception {
BeanDescription desc = MAPPER.getDeserializationConfig().introspect(MAPPER.constructType(ImplController.class));
AnnotatedClass ac = desc.getClassInfo();
AnnotatedMethod m = ac.findMethod("process", new Class<?>[] { BaseEntity.class });
assertNotNull(m);
assertEquals(1, m.getParameterCount());
AnnotatedParameter param = m.getParameter(0);
assertEquals(ImplEntity.class, param.getType().getRawClass());
}
use of com.fasterxml.jackson.databind.introspect.AnnotatedClass in project crnk-framework by crnk-project.
the class JacksonResourceFieldInformationProvider method getName.
protected Optional<String> getName(Field field) {
ObjectMapper objectMapper = context.getObjectMapper();
SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) {
AnnotationMap annotationMap = buildAnnotationMap(field.getDeclaredAnnotations());
AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(field.getDeclaringClass(), serializationConfig);
AnnotatedField annotatedField = AnnotatedFieldBuilder.build(annotatedClass, field, annotationMap);
return Optional.of(serializationConfig.getPropertyNamingStrategy().nameForField(serializationConfig, annotatedField, field.getName()));
}
return Optional.empty();
}
use of com.fasterxml.jackson.databind.introspect.AnnotatedClass in project endpoints-java by cloudendpoints.
the class ApiAnnotationIntrospector method findSerializerInstance.
@Nullable
private Transformer<?, ?> findSerializerInstance(Annotated a) {
if (a instanceof AnnotatedClass) {
AnnotatedClass clazz = (AnnotatedClass) a;
List<Class<? extends Transformer<?, ?>>> serializerClasses = Serializers.getSerializerClasses(clazz.getRawType(), config);
if (!serializerClasses.isEmpty()) {
return Serializers.instantiate(serializerClasses.get(0), TypeToken.of(a.getRawType()));
}
}
return null;
}
Aggregations