use of com.fasterxml.jackson.databind.introspect.AnnotatedField 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.AnnotatedField in project swagger-core by swagger-api.
the class DefaultParameterExtension method handleAdditionalAnnotation.
/**
* Adds additional annotation processing support
*
* @param parameters
* @param annotation
* @param type
* @param typesToSkip
*/
private void handleAdditionalAnnotation(List<Parameter> parameters, Annotation annotation, final Type type, Set<Type> typesToSkip) {
if (CLASS_BEAN_PARAM != null && CLASS_BEAN_PARAM.isAssignableFrom(annotation.getClass())) {
// Use Jackson's logic for processing Beans
final BeanDescription beanDesc = mapper.getSerializationConfig().introspect(constructType(type));
final List<BeanPropertyDefinition> properties = beanDesc.findProperties();
for (final BeanPropertyDefinition propDef : properties) {
final AnnotatedField field = propDef.getField();
final AnnotatedMethod setter = propDef.getSetter();
final AnnotatedMethod getter = propDef.getGetter();
final List<Annotation> paramAnnotations = new ArrayList<Annotation>();
final Iterator<SwaggerExtension> extensions = SwaggerExtensions.chain();
Type paramType = null;
// Gather the field's details
if (field != null) {
paramType = field.getRawType();
for (final Annotation fieldAnnotation : field.annotations()) {
if (!paramAnnotations.contains(fieldAnnotation)) {
paramAnnotations.add(fieldAnnotation);
}
}
}
// Gather the setter's details but only the ones we need
if (setter != null) {
// Do not set the param class/type from the setter if the values are already identified
if (paramType == null) {
paramType = setter.getRawParameterTypes() != null ? setter.getRawParameterTypes()[0] : null;
}
for (final Annotation fieldAnnotation : setter.annotations()) {
if (!paramAnnotations.contains(fieldAnnotation)) {
paramAnnotations.add(fieldAnnotation);
}
}
}
// Gather the getter's details but only the ones we need
if (getter != null) {
// Do not set the param class/type from the getter if the values are already identified
if (paramType == null) {
paramType = getter.getRawReturnType();
}
for (final Annotation fieldAnnotation : getter.annotations()) {
if (!paramAnnotations.contains(fieldAnnotation)) {
paramAnnotations.add(fieldAnnotation);
}
}
}
if (paramType == null) {
continue;
}
// Re-process all Bean fields and let the default swagger-jaxrs/swagger-jersey-jaxrs processors do their thing
List<Parameter> extracted = extensions.next().extractParameters(paramAnnotations, paramType, typesToSkip, extensions);
// since downstream processors won't know how to introspect @BeanParam, process here
for (Parameter param : extracted) {
if (ParameterProcessor.applyAnnotations(null, param, paramType, paramAnnotations) != null) {
parameters.add(param);
}
}
}
}
}
use of com.fasterxml.jackson.databind.introspect.AnnotatedField 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.AnnotatedField in project jackson-module-afterburner by FasterXML.
the class PropertyAccessorCollector method _addSingleField.
private void _addSingleField(MethodVisitor mv, OptimizedBeanPropertyWriter<?> prop, int returnOpcode) {
// load second arg (index)
mv.visitVarInsn(ILOAD, 2);
// load local for cast bean
mv.visitVarInsn(ALOAD, 3);
AnnotatedField field = (AnnotatedField) prop.getMember();
mv.visitFieldInsn(GETFIELD, beanClassName, field.getName(), Type.getDescriptor(field.getRawType()));
mv.visitInsn(returnOpcode);
}
use of com.fasterxml.jackson.databind.introspect.AnnotatedField in project jackson-module-afterburner by FasterXML.
the class PropertyMutatorCollector method _addFieldsUsingSwitch.
private <T extends OptimizedSettableBeanProperty<T>> void _addFieldsUsingSwitch(MethodVisitor mv, List<T> props, int loadValueCode, int beanIndex, boolean mustCast) {
// load second arg (index)
mv.visitVarInsn(ILOAD, 2);
Label[] labels = new Label[props.size()];
for (int i = 0, len = labels.length; i < len; ++i) {
labels[i] = new Label();
}
Label defaultLabel = new Label();
mv.visitTableSwitchInsn(0, labels.length - 1, defaultLabel, labels);
for (int i = 0, len = labels.length; i < len; ++i) {
mv.visitLabel(labels[i]);
// load bean
mv.visitVarInsn(ALOAD, beanIndex);
// put 'value' to stack
mv.visitVarInsn(loadValueCode, 3);
AnnotatedField field = (AnnotatedField) props.get(i).getMember();
Type type = Type.getType(field.getRawType());
if (mustCast) {
mv.visitTypeInsn(CHECKCAST, type.getInternalName());
}
mv.visitFieldInsn(PUTFIELD, beanClassName, field.getName(), type.getDescriptor());
mv.visitInsn(RETURN);
}
mv.visitLabel(defaultLabel);
}
Aggregations