use of com.fasterxml.jackson.databind.introspect.AnnotatedMethod 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.AnnotatedMethod 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.AnnotatedMethod 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.AnnotatedMethod in project jackson-module-afterburner by FasterXML.
the class TestAccessorGeneration method testLotsaIntAccessorGeneration.
// And then test to ensure Switch-table construction also works...
public void testLotsaIntAccessorGeneration() throws Exception {
PropertyAccessorCollector coll = new PropertyAccessorCollector(BeanN.class);
String[] methodNames = new String[] { "getX", "getY", "get3", "get4", "get5", "get6", "get7" };
for (String methodName : methodNames) {
Method method = BeanN.class.getDeclaredMethod(methodName);
AnnotatedMethod annMethod = new AnnotatedMethod(null, method, null, null);
coll.addIntGetter(new BeanPropertyWriter(SimpleBeanPropertyDefinition.construct(null, annMethod, new PropertyName(methodName)), annMethod, null, null, null, null, null, false, null));
}
BeanPropertyAccessor acc = coll.findAccessor(null);
BeanN bean = new BeanN();
assertEquals(bean.getX(), acc.intGetter(bean, 0));
assertEquals(bean.getY(), acc.intGetter(bean, 1));
assertEquals(bean.get3(), acc.intGetter(bean, 2));
assertEquals(bean.get4(), acc.intGetter(bean, 3));
assertEquals(bean.get5(), acc.intGetter(bean, 4));
assertEquals(bean.get6(), acc.intGetter(bean, 5));
assertEquals(bean.get7(), acc.intGetter(bean, 6));
}
use of com.fasterxml.jackson.databind.introspect.AnnotatedMethod in project jackson-databind by FasterXML.
the class SettableAnyProperty method set.
@SuppressWarnings("unchecked")
public void set(Object instance, Object propName, Object value) throws IOException {
try {
// if annotation in the field (only map is supported now)
if (_setterIsField) {
AnnotatedField field = (AnnotatedField) _setter;
Map<Object, Object> val = (Map<Object, Object>) field.getValue(instance);
/* 01-Jun-2016, tatu: At this point it is not quite clear what to do if
* field is `null` -- we can not necessarily count on zero-args
* constructor except for a small set of types, so for now just
* ignore if null. May need to figure out something better in future.
*/
if (val != null) {
// add the property key and value
val.put(propName, value);
}
} else {
// note: can not use 'setValue()' due to taking 2 args
((AnnotatedMethod) _setter).callOnWith(instance, propName, value);
}
} catch (Exception e) {
_throwAsIOE(e, propName, value);
}
}
Aggregations