use of com.fasterxml.jackson.annotation.JsonFilter 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);
}
}
}
Aggregations