com.fasterxml.jackson.annotation.JsonManagedReference Java Examples

The following examples show how to use com.fasterxml.jackson.annotation.JsonManagedReference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BiDirectionalCollectionResolver.java    From minnal with Apache License 2.0 6 votes vote down vote up
@Override
protected void setAttribute(Object pojo, AttributeMetaData attribute, Object value) {
    super.setAttribute(pojo, attribute, value);
    JsonManagedReference managedReference = attribute.getAnnotation(JsonManagedReference.class);
    if (managedReference != null && value != null) {
        Class<?> elementType = (Class<?>) attribute.getTypeArguments()[0];
        PropertyDescriptor backReference = getManagedBackReference(elementType, managedReference.value());
        if (backReference != null) {
            Collection collection = (Collection) value;
            for (Object object : collection) {
                try {
                    PropertyUtils.setProperty(object, backReference.getName(), pojo);
                } catch (Exception e) {
                    logger.info("Failed while setting the property {} on the class {}", backReference.getName(), value.getClass());
                }
            }

        }
    }
}
 
Example #2
Source File: JsonViewSerializer.java    From json-view with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a boolean indicating whether the provided field is annotated with
 * some form of ignore. This method is memoized to speed up execution time
 */
boolean annotatedWithIgnore(AccessibleProperty f) {
  return memoizer.annotatedWithIgnore(f, () -> {
    JsonIgnore jsonIgnore = getAnnotation(f, JsonIgnore.class);
    JsonIgnoreProperties classIgnoreProperties = getAnnotation(f.declaringClass, JsonIgnoreProperties.class);
    JsonIgnoreProperties fieldIgnoreProperties = null;
    boolean backReferenced = false;

    //make sure the referring field didn't specify properties to ignore
    if(referringField != null) {
      fieldIgnoreProperties = getAnnotation(referringField, JsonIgnoreProperties.class);
    }

    //make sure the referring field didn't specify a backreference annotation
    if(getAnnotation(f, JsonBackReference.class) != null && referringField != null) {
      for(AccessibleProperty lastField : getAccessibleProperties(referringField.declaringClass)) {
        JsonManagedReference fieldManagedReference = getAnnotation(lastField, JsonManagedReference.class);
        if(fieldManagedReference != null && lastField.type.equals(f.declaringClass)) {
          backReferenced = true;
          break;
        }
      }
    }

    return (jsonIgnore != null && jsonIgnore.value()) ||
        (classIgnoreProperties != null && asList(classIgnoreProperties.value()).contains(f.name)) ||
        (fieldIgnoreProperties != null && asList(fieldIgnoreProperties.value()).contains(f.name)) ||
        backReferenced;
  });
}
 
Example #3
Source File: BiDirectionalObjectResolver.java    From minnal with Apache License 2.0 5 votes vote down vote up
@Override
protected void setAttribute(Object pojo, AttributeMetaData attribute, Object value) {
    super.setAttribute(pojo, attribute, value);
    JsonManagedReference managedReference = attribute.getAnnotation(JsonManagedReference.class);
    if (managedReference != null && value != null) {
        PropertyDescriptor backReference = getManagedBackReference(value.getClass(), managedReference.value());
        if (backReference != null) {
            try {
                PropertyUtils.setProperty(value, backReference.getName(), pojo);
            } catch (Exception e) {
                logger.info("Failed while setting the property {} on the class {}", backReference.getName(), value.getClass());
            }
        }
    }
}
 
Example #4
Source File: GMailMessageActivitySerializer.java    From streams with Apache License 2.0 4 votes vote down vote up
@JsonManagedReference
@JsonIgnore
@JsonProperty("parent")
@JsonBackReference
MimeMultipart getParent();
 
Example #5
Source File: ApigeeApp.java    From apigee-android-sdk with Apache License 2.0 4 votes vote down vote up
@JsonManagedReference
public Set<AppConfigOverrideFilter> getAppConfigOverrideFilters() {
	return appConfigOverrideFilters;
}
 
Example #6
Source File: Author.java    From tutorials with MIT License 4 votes vote down vote up
@JsonManagedReference
public List<Item> getItems() {
    return items;
}
 
Example #7
Source File: JsonManagedAndBackReferenceTester.java    From gwt-jackson with Apache License 2.0 4 votes vote down vote up
@JsonManagedReference
public SimpleTreeNode2 getChild() {
    return child;
}
 
Example #8
Source File: PropertyProcessor.java    From gwt-jackson with Apache License 2.0 4 votes vote down vote up
private static Optional<PropertyInfo> processProperty( RebindConfiguration configuration, TreeLogger logger, JacksonTypeOracle
        typeOracle, PropertyAccessors propertyAccessors, BeanInfo beanInfo, boolean samePackage ) throws UnableToCompleteException {

    boolean getterAutoDetected = isGetterAutoDetected( configuration, propertyAccessors, beanInfo );
    boolean setterAutoDetected = isSetterAutoDetected( configuration, propertyAccessors, beanInfo );
    boolean fieldAutoDetected = isFieldAutoDetected( configuration, propertyAccessors, beanInfo );

    if ( !getterAutoDetected && !setterAutoDetected && !fieldAutoDetected && !propertyAccessors.getParameter().isPresent() ) {
        // none of the field have been auto-detected, we ignore the field
        return Optional.absent();
    }

    final String propertyName = propertyAccessors.getPropertyName();
    final JType type = findType( logger, propertyAccessors, typeOracle, getterAutoDetected, setterAutoDetected, fieldAutoDetected );

    PropertyInfoBuilder builder = new PropertyInfoBuilder( propertyName, type );

    builder.setIgnored( isPropertyIgnored( configuration, propertyAccessors, beanInfo, type, propertyName ) );
    if ( builder.isIgnored() ) {
        return Optional.of( builder.build() );
    }

    Optional<JsonProperty> jsonProperty = propertyAccessors.getAnnotation( JsonProperty.class );
    builder.setRequired( jsonProperty.isPresent() && jsonProperty.get().required() );

    Optional<JsonManagedReference> jsonManagedReference = propertyAccessors.getAnnotation( JsonManagedReference.class );
    builder.setManagedReference( Optional.fromNullable( jsonManagedReference.isPresent() ? jsonManagedReference.get()
            .value() : null ) );

    Optional<JsonBackReference> jsonBackReference = propertyAccessors.getAnnotation( JsonBackReference.class );
    builder.setBackReference( Optional.fromNullable( jsonBackReference.isPresent() ? jsonBackReference.get().value() : null ) );

    if ( !builder.getBackReference().isPresent() ) {
        determineGetter( propertyAccessors, samePackage, getterAutoDetected, fieldAutoDetected, builder );

        Optional<JsonRawValue> jsonRawValue = propertyAccessors.getAnnotation( JsonRawValue.class );
        builder.setRawValue( jsonRawValue.isPresent() && jsonRawValue.get().value() );
    }
    determineSetter( propertyAccessors, samePackage, setterAutoDetected, fieldAutoDetected, builder );

    Optional<JsonValue> jsonValue = propertyAccessors.getAnnotation( JsonValue.class );
    if ( jsonValue.isPresent() && jsonValue.get().value() && builder.getGetterAccessor().isPresent() && builder.getGetterAccessor()
            .get().getMethod().isPresent() ) {
        builder.setValue( true );
    }

    Optional<JsonAnyGetter> jsonAnyGetter = propertyAccessors.getAnnotation( JsonAnyGetter.class );
    if ( jsonAnyGetter.isPresent() && builder.getGetterAccessor().isPresent() && builder.getGetterAccessor().get().getMethod()
            .isPresent() ) {
        builder.setAnyGetter( true );
    }

    Optional<JsonAnySetter> jsonAnySetter = propertyAccessors.getAnnotation( JsonAnySetter.class );
    if ( jsonAnySetter.isPresent() && builder.getSetterAccessor().isPresent() && builder.getSetterAccessor().get().getMethod()
            .isPresent() && builder.getSetterAccessor().get().getMethod().get().getParameterTypes().length == 2 ) {
        builder.setAnySetter( true );
    }

    Optional<JsonUnwrapped> jsonUnwrapped = propertyAccessors.getAnnotation( JsonUnwrapped.class );
    if ( jsonUnwrapped.isPresent() && jsonUnwrapped.get().enabled() ) {
        builder.setUnwrapped( true );
    }

    processBeanAnnotation( logger, typeOracle, configuration, type, propertyAccessors, builder );

    builder.setFormat( propertyAccessors.getAnnotation( JsonFormat.class ) );

    Optional<JsonInclude> jsonInclude = propertyAccessors.getAnnotation( JsonInclude.class );
    if ( jsonInclude.isPresent() ) {
        builder.setInclude( Optional.of( jsonInclude.get().value() ) );
    } else {
        builder.setInclude( beanInfo.getInclude() );
    }

    Optional<JsonIgnoreProperties> jsonIgnoreProperties = propertyAccessors.getAnnotation( JsonIgnoreProperties.class );
    if ( jsonIgnoreProperties.isPresent() ) {
        builder.setIgnoreUnknown( Optional.of( jsonIgnoreProperties.get().ignoreUnknown() ) );
        if ( null != jsonIgnoreProperties.get().value() && jsonIgnoreProperties.get().value().length > 0 ) {
            builder.setIgnoredProperties( Optional.of( jsonIgnoreProperties.get().value() ) );
        }
    }

    return Optional.of( builder.build() );
}
 
Example #9
Source File: JpaRegion.java    From attic-rave with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the ordered list of widget instances for the region
 *
 * @return Valid list
 */
@Override
@JsonManagedReference
public List<RegionWidget> getRegionWidgets() {
    return ConvertingListProxyFactory.createProxyList(RegionWidget.class, regionWidgets);
}
 
Example #10
Source File: JpaPage.java    From attic-rave with Apache License 2.0 4 votes vote down vote up
@Override
@JsonManagedReference
public List<PageUser> getMembers() {
    return ConvertingListProxyFactory.createProxyList(PageUser.class, members);
}
 
Example #11
Source File: JpaPage.java    From attic-rave with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the widget containing {@link Region}s of the page
 *
 * @return Valid list of {@link Region}s
 */
@Override
@JsonManagedReference
public List<Region> getRegions() {
    return ConvertingListProxyFactory.createProxyList(Region.class, regions);
}
 
Example #12
Source File: TUser.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
@JsonManagedReference
public Set<TArticle> getArticles() {
    return articles;
}
 
Example #13
Source File: GMailMessageActivitySerializer.java    From streams with Apache License 2.0 4 votes vote down vote up
@JsonManagedReference
@JsonIgnore
@JsonBackReference
IMAPMessage getFolder();
 
Example #14
Source File: GMailMessageActivitySerializer.java    From streams with Apache License 2.0 4 votes vote down vote up
@JsonManagedReference
@JsonIgnore
IMAPFolder getStore();
 
Example #15
Source File: GMailMessageActivitySerializer.java    From streams with Apache License 2.0 4 votes vote down vote up
@JsonManagedReference
@JsonIgnore
IMAPSSLStore getDefaultFolder();
 
Example #16
Source File: Drop.java    From mojito with Apache License 2.0 4 votes vote down vote up
@JsonManagedReference
public Set<TranslationKit> getTranslationKits() {
    return translationKits;
}
 
Example #17
Source File: BookedTrip.java    From Spring-MVC-Blueprints with MIT License 4 votes vote down vote up
@JsonManagedReference("booked-data")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "tripId", nullable = false)
public Trip getTrip() {
	return this.trip;
}
 
Example #18
Source File: BookedTrip.java    From Spring-MVC-Blueprints with MIT License 4 votes vote down vote up
@JsonManagedReference("customer-data")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "userId", nullable = false)
public CustomerInfo getCustomerInfo() {
	return this.customerInfo;
}
 
Example #19
Source File: GMailMessageActivitySerializer.java    From streams with Apache License 2.0 3 votes vote down vote up
@JsonManagedReference
@JsonIgnore
IMAPSSLStore getPersonalNamespaces();