Search in sources :

Example 1 with JsonBackReference

use of com.fasterxml.jackson.annotation.JsonBackReference in project jsonschema-generator by victools.

the class JacksonModule method shouldIgnoreField.

/**
 * Determine whether a given field should be ignored, according to various jackson annotations for that purpose,
 * <br>
 * e.g. {@code JsonBackReference}, {@code JsonIgnore}, {@code JsonIgnoreType}, {@code JsonIgnoreProperties}
 *
 * @param field field to check
 * @return whether field should be excluded
 */
protected boolean shouldIgnoreField(FieldScope field) {
    if (field.getAnnotationConsideringFieldAndGetterIfSupported(JsonBackReference.class) != null) {
        return true;
    }
    // instead of re-creating the various ways a property may be included/excluded in jackson: just use its built-in introspection
    BeanDescription beanDescription = this.getBeanDescriptionForClass(field.getDeclaringType());
    // some kinds of field ignorals are only available via an annotation introspector
    Set<String> ignoredProperties = this.objectMapper.getSerializationConfig().getAnnotationIntrospector().findPropertyIgnoralByName(null, beanDescription.getClassInfo()).getIgnored();
    String fieldName = field.getName();
    if (ignoredProperties.contains(fieldName)) {
        return true;
    }
    // other kinds of field ignorals are handled implicitly, i.e. are only available by way of being absent
    return beanDescription.findProperties().stream().noneMatch(propertyDefinition -> fieldName.equals(propertyDefinition.getInternalName()));
}
Also used : JsonBackReference(com.fasterxml.jackson.annotation.JsonBackReference) BeanDescription(com.fasterxml.jackson.databind.BeanDescription)

Example 2 with JsonBackReference

use of com.fasterxml.jackson.annotation.JsonBackReference in project ddf-common by dongfangding.

the class JacksonAnnotationIntrospector method findReferenceType.

@Override
public ReferenceProperty findReferenceType(AnnotatedMember member) {
    JsonManagedReference ref1 = _findAnnotation(member, JsonManagedReference.class);
    if (ref1 != null) {
        return ReferenceProperty.managed(ref1.value());
    }
    JsonBackReference ref2 = _findAnnotation(member, JsonBackReference.class);
    if (ref2 != null) {
        return ReferenceProperty.back(ref2.value());
    }
    return null;
}
Also used : JsonManagedReference(com.fasterxml.jackson.annotation.JsonManagedReference) JsonBackReference(com.fasterxml.jackson.annotation.JsonBackReference)

Aggregations

JsonBackReference (com.fasterxml.jackson.annotation.JsonBackReference)2 JsonManagedReference (com.fasterxml.jackson.annotation.JsonManagedReference)1 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)1