use of com.fasterxml.jackson.databind.introspect.AnnotatedMember in project jackson-databind by FasterXML.
the class MapDeserializer method createContextual.
/**
* Method called to finalize setup of this deserializer,
* when it is known for which property deserializer is needed for.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
KeyDeserializer keyDeser = _keyDeserializer;
if (keyDeser == null) {
keyDeser = ctxt.findKeyDeserializer(_containerType.getKeyType(), property);
} else {
if (keyDeser instanceof ContextualKeyDeserializer) {
keyDeser = ((ContextualKeyDeserializer) keyDeser).createContextual(ctxt, property);
}
}
JsonDeserializer<?> valueDeser = _valueDeserializer;
// [databind#125]: May have a content converter
if (property != null) {
valueDeser = findConvertingContentDeserializer(ctxt, property, valueDeser);
}
final JavaType vt = _containerType.getContentType();
if (valueDeser == null) {
valueDeser = ctxt.findContextualValueDeserializer(vt, property);
} else {
// if directly assigned, probably not yet contextual, so:
valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt);
}
TypeDeserializer vtd = _valueTypeDeserializer;
if (vtd != null) {
vtd = vtd.forProperty(property);
}
Set<String> ignored = _ignorableProperties;
AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
if (intr != null && property != null) {
AnnotatedMember member = property.getMember();
if (member != null) {
JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnorals(member);
if (ignorals != null) {
Set<String> ignoresToAdd = ignorals.findIgnoredForDeserialization();
if (!ignoresToAdd.isEmpty()) {
ignored = (ignored == null) ? new HashSet<String>() : new HashSet<String>(ignored);
for (String str : ignoresToAdd) {
ignored.add(str);
}
}
}
}
}
return withResolved(keyDeser, vtd, valueDeser, findContentNullProvider(ctxt, property, valueDeser), ignored);
}
use of com.fasterxml.jackson.databind.introspect.AnnotatedMember in project candlepin by candlepin.
the class CandlepinSwaggerModelConverter method parseProperty.
private void parseProperty(ModelConverterContext context, boolean isNested, final BeanDescription beanDesc, Set<String> propertiesToIgnore, List<Property> props, BeanPropertyDefinition propDef) {
Property property = null;
String propName = propDef.getName();
Annotation[] annotations = null;
propName = getPropName(propDef, propName);
PropertyMetadata md = propDef.getMetadata();
boolean hasSetter = false, hasGetter = false;
if (propDef.getSetter() == null) {
hasSetter = false;
} else {
hasSetter = true;
}
if (propDef.getGetter() != null) {
JsonProperty pd = propDef.getGetter().getAnnotation(JsonProperty.class);
if (pd != null) {
hasGetter = true;
}
}
Boolean isReadOnly = null;
if (!hasSetter & hasGetter) {
isReadOnly = Boolean.TRUE;
} else {
isReadOnly = Boolean.FALSE;
}
final AnnotatedMember member = propDef.getPrimaryMember();
if (member != null && !propertiesToIgnore.contains(propName) && /**
* If the owning type is nested than we should include only those
* fields that have the Hateoas annotation.
*/
!(isNested && !member.hasAnnotation(HateoasInclude.class))) {
List<Annotation> annotationList = new ArrayList<>();
for (Annotation a : member.annotations()) {
annotationList.add(a);
}
annotations = annotationList.toArray(new Annotation[annotationList.size()]);
ApiModelProperty mp = member.getAnnotation(ApiModelProperty.class);
if (mp != null && mp.readOnly()) {
isReadOnly = mp.readOnly();
}
Type nested = null;
JavaType propType = member.getType(beanDesc.bindingsForBeanType());
JsonFilter jsonFilter = propType.getRawClass().getAnnotation(JsonFilter.class);
/**
* At this point the propType is a type of some nested field of the
* type that is being processed. The condition checks if this
* particular type should have Hateoas serialization enabled. In
* other words, if we should create a new Nested* model.
*/
if (jsonFilter != null && (jsonFilter.value().equals("ConsumerFilter") || jsonFilter.value().equals("EntitlementFilter") || jsonFilter.value().equals("OwnerFilter") || jsonFilter.value().equals("GuestFilter"))) {
if (!nestedJavaTypes.containsKey(propType)) {
nestedJavaTypes.put(propType, new NestedComplexType(propType));
}
nested = nestedJavaTypes.get(propType);
} else {
nested = propType;
}
// allow override of name from annotation
if (mp != null && !mp.name().isEmpty()) {
propName = mp.name();
}
if (mp != null && !mp.dataType().isEmpty()) {
property = resolveApiAnnotated(context, property, annotations, mp, propType);
}
// no property from override, construct from propType
if (property == null) {
if (mp != null && StringUtils.isNotEmpty(mp.reference())) {
property = new RefProperty(mp.reference());
} else if (member.getAnnotation(JsonIdentityInfo.class) != null) {
property = GeneratorWrapper.processJsonIdentity(propType, context, pMapper, member.getAnnotation(JsonIdentityInfo.class), member.getAnnotation(JsonIdentityReference.class));
}
if (property == null) {
property = context.resolveProperty(nested, annotations);
}
}
if (property != null) {
addMetadataToProperty(property, propName, md, isReadOnly, member, mp);
applyBeanValidatorAnnotations(property, annotations);
props.add(property);
}
}
}
use of com.fasterxml.jackson.databind.introspect.AnnotatedMember in project fabric8 by fabric8io.
the class BeanValidationAnnotationIntrospector method hasIgnoreMarker.
@Override
public boolean hasIgnoreMarker(AnnotatedMember m) {
Member member = m.getMember();
int modifiers = member.getModifiers();
if (Modifier.isTransient(modifiers)) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Ignoring transient member " + m);
}
return true;
} else if (m instanceof AnnotatedMethod) {
AnnotatedMethod method = (AnnotatedMethod) m;
String methodName = method.getName();
// lets see if there is a transient field of the same name as the getter
if (methodName.startsWith("get") && method.getParameterCount() == 0) {
String fieldName = Introspector.decapitalize(methodName.substring(3));
Class<?> declaringClass = method.getDeclaringClass();
Field field = findField(fieldName, declaringClass);
if (field != null) {
int fieldModifiers = field.getModifiers();
if (Modifier.isTransient(fieldModifiers)) {
LOG.fine("Ignoring member " + m + " due to transient field called " + fieldName);
return true;
}
}
}
}
return super.hasIgnoreMarker(m);
}
use of com.fasterxml.jackson.databind.introspect.AnnotatedMember in project beam by apache.
the class PipelineOptionsFactory method computeCustomSerializerForMethod.
private static Optional<JsonSerializer<Object>> computeCustomSerializerForMethod(Method method) {
try {
BeanProperty prop = createBeanProperty(method);
AnnotatedMember annotatedMethod = prop.getMember();
Object maybeSerializerClass = SERIALIZER_PROVIDER.getAnnotationIntrospector().findSerializer(annotatedMethod);
return Optional.fromNullable(SERIALIZER_PROVIDER.serializerInstance(annotatedMethod, maybeSerializerClass));
} catch (JsonMappingException e) {
throw new RuntimeException(e);
}
}
use of com.fasterxml.jackson.databind.introspect.AnnotatedMember in project zm-mailbox by Zimbra.
the class ZimbraBeanSerializerModifier method changeProperties.
/*
/**********************************************************
/* Overridden methods
/**********************************************************
*/
/**
* First thing to do is to find annotations regarding XML serialization,
* and wrap collection serializers.
*/
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
AnnotationIntrospector intr = config.getAnnotationIntrospector();
for (int i = 0, len = beanProperties.size(); i < len; ++i) {
BeanPropertyWriter bpw = beanProperties.get(i);
final AnnotatedMember member = bpw.getMember();
NameInfo nameInfo = new NameInfo(intr, member, bpw.getName());
if (!nameInfo.needSpecialHandling()) {
continue;
}
beanProperties.set(i, new ZimbraBeanPropertyWriter(bpw, nameInfo));
}
return beanProperties;
}
Aggregations