类com.fasterxml.jackson.annotation.JsonBackReference源码实例Demo

下面列出了怎么用com.fasterxml.jackson.annotation.JsonBackReference的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jsonschema-generator   文件: JacksonModule.java
/**
 * 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.getAnnotationConsideringFieldAndGetter(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()
            .findPropertyIgnorals(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()));
}
 
源代码2 项目: json-view   文件: JsonViewSerializer.java
/**
 * 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;
  });
}
 
源代码3 项目: minnal   文件: BiDirectionalObjectResolver.java
private PropertyDescriptor getManagedBackReference(Class<?> clazz, String name) {
    List<PropertyDescriptor> descriptors = PropertyUtil.getPopertiesWithAnnotation(clazz, JsonBackReference.class);
    if (descriptors != null) {
        for (PropertyDescriptor descriptor : descriptors) {
            JsonBackReference backReference = PropertyUtil.getAnnotation(descriptor, JsonBackReference.class);
            if (backReference.value().equals(name)) {
                return descriptor;
            }
        }
    }
    return null;
}
 
源代码4 项目: minnal   文件: BiDirectionalCollectionResolver.java
private PropertyDescriptor getManagedBackReference(Class<?> clazz, String name) {
    List<PropertyDescriptor> descriptors = PropertyUtil.getPopertiesWithAnnotation(clazz, JsonBackReference.class);
    if (descriptors != null) {
        for (PropertyDescriptor descriptor : descriptors) {
            JsonBackReference backReference = PropertyUtil.getAnnotation(descriptor, JsonBackReference.class);
            if (backReference.value().equals(name)) {
                return descriptor;
            }
        }
    }
    return null;
}
 
源代码5 项目: minnal   文件: ExcludeAnnotationsConvertorTest.java
@BeforeMethod
public void setup() {
	convertor = spy(new ExcludeAnnotationsConvertor(Lists.<Class<? extends Annotation>>newArrayList(JsonBackReference.class)));
	model = mock(Model.class);
	properties = mock(LinkedHashMap.class);
	when(model.properties()).thenReturn(properties);
}
 
源代码6 项目: activiti6-boot2   文件: Lane.java
@JsonBackReference
public Process getParentProcess() {
  return parentProcess;
}
 
源代码7 项目: AsuraFramework   文件: TArticle.java
@JsonBackReference
public TUser getUser() {
    return user;
}
 
源代码8 项目: Spring-MVC-Blueprints   文件: PaymentAp.java
@XmlTransient
   @JsonBackReference("paymentAp")
@OneToMany(fetch = FetchType.LAZY, mappedBy = "paymentAp")
public Set<Invoice> getInvoices() {
	return this.invoices;
}
 
源代码9 项目: Spring-MVC-Blueprints   文件: PaymentAp.java
@XmlTransient
   @JsonBackReference("paymentAp")
@OneToMany(fetch = FetchType.LAZY, mappedBy = "paymentAp")
public Set<Invoice> getInvoices() {
	return this.invoices;
}
 
源代码10 项目: Spring-MVC-Blueprints   文件: StationDetail.java
@JsonBackReference("trips-data")
@OneToMany(fetch = FetchType.LAZY, mappedBy = "stationDetail")
public Set<Trip> getTrips() {
	return this.trips;
}
 
源代码11 项目: Spring-MVC-Blueprints   文件: CustomerInfo.java
@JsonBackReference("customer-data")
@OneToMany(fetch = FetchType.LAZY, mappedBy = "customerInfo")
public Set<BookedTrip> getBookedTrips() {
	return this.bookedTrips;
}
 
源代码12 项目: Spring-MVC-Blueprints   文件: Trip.java
@JsonBackReference("trips-data")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "stationId", nullable = false)
public StationDetail getStationDetail() {
	return this.stationDetail;
}
 
源代码13 项目: Spring-MVC-Blueprints   文件: Trip.java
@JsonBackReference("booked-data")
@OneToMany(fetch = FetchType.LAZY, mappedBy = "trip")
public Set<BookedTrip> getBookedTrips() {
	return this.bookedTrips;
}
 
源代码14 项目: Shop-for-JavaWeb   文件: ActUtils.java
@SuppressWarnings({ "unused" })
public static Map<String, Object> getMobileEntity(Object entity,String spiltType){
	if(spiltType==null){
		spiltType="@";
	}
	Map<String, Object> map = Maps.newHashMap();

	List<String> field = Lists.newArrayList();
	List<String> value = Lists.newArrayList();
	List<String> chinesName =Lists.newArrayList();
	
	try{
		for (Method m : entity.getClass().getMethods()){
			if (m.getAnnotation(JsonIgnore.class) == null && m.getAnnotation(JsonBackReference.class) == null && m.getName().startsWith("get")){
				if (m.isAnnotationPresent(FieldName.class)) {
					Annotation p = m.getAnnotation(FieldName.class);
					FieldName fieldName=(FieldName) p;
					chinesName.add(fieldName.value());
				}else{
					chinesName.add("");
				}
				if (m.getName().equals("getAct")){
					Object act = m.invoke(entity, new Object[]{});
					Method actMet = act.getClass().getMethod("getTaskId");
					map.put("taskId", ObjectUtils.toString(m.invoke(act, new Object[]{}), ""));
				}else{
					field.add(StringUtils.uncapitalize(m.getName().substring(3)));
					value.add(ObjectUtils.toString(m.invoke(entity, new Object[]{}), ""));
				}
			}
		}
	}catch (Exception e) {
		e.printStackTrace();
	}
	
	map.put("beanTitles", StringUtils.join(field, spiltType));
	map.put("beanInfos", StringUtils.join(value, spiltType));
	map.put("chineseNames", StringUtils.join(chinesName, spiltType));
	
	return map;
}
 
源代码15 项目: Shop-for-JavaWeb   文件: Menu.java
@JsonBackReference
@NotNull
public Menu getParent() {
	return parent;
}
 
源代码16 项目: flowable-engine   文件: Lane.java
@JsonBackReference
public Process getParentProcess() {
    return parentProcess;
}
 
源代码17 项目: ameliant-tools   文件: ConfigurableWithParent.java
@JsonBackReference
public void setParent(Configurable parent) {
    this.parent = parent;
}
 
源代码18 项目: streams   文件: GMailMessageActivitySerializer.java
@JsonManagedReference
@JsonIgnore
@JsonBackReference
IMAPMessage getFolder();
 
源代码19 项目: streams   文件: GMailMessageActivitySerializer.java
@JsonManagedReference
@JsonIgnore
@JsonProperty("parent")
@JsonBackReference
MimeMultipart getParent();
 
源代码20 项目: attic-rave   文件: RegionImpl.java
@Override
@JsonBackReference
public Page getPage() {
    return page;
}
 
源代码21 项目: attic-rave   文件: JpaRegionWidget.java
/**
 * Gets the associated region
 *
 * @return the region
 */
@Override
@JsonBackReference
public Region getRegion() {
    return region;
}
 
源代码22 项目: attic-rave   文件: JpaPageUser.java
/**
* @return the page
*/
@Override
@JsonBackReference
public Page getPage() {
    return page;
}
 
源代码23 项目: attic-rave   文件: JpaRegion.java
/**
 * Gets the associated page
 *
 * @return the associated page
 */
@Override
@JsonBackReference
public Page getPage() {
    return page;
}
 
源代码24 项目: attic-rave   文件: RegionWidget.java
@JsonBackReference
Region getRegion();
 
源代码25 项目: minnal   文件: ApiBundle.java
/**
 * Returns the model convertor
 * 
 * @return
 */
protected ExcludeAnnotationsConvertor getExcludeAnnotationsConvertor() {
	List<Class<? extends Annotation>> excludedAnnotations = Lists.<Class<? extends Annotation>>newArrayList(JsonBackReference.class);
	excludedAnnotations.addAll(configuration.getExcludedAnnotations());
	return new ExcludeAnnotationsConvertor(excludedAnnotations);
}
 
源代码26 项目: minnal   文件: ApiBundleTest.java
@Test
public void shouldGetExcludeAnnotationsConverter() {
	apiBundle.init(container, bundleConfiguration);
	ExcludeAnnotationsConvertor convertor = apiBundle.getExcludeAnnotationsConvertor();
	assertEquals(convertor.getExcludeAnnotations(), Lists.newArrayList(JsonBackReference.class, JsonIgnore.class));
}
 
源代码27 项目: minnal   文件: ExcludeAnnotationsConvertorTest.java
/**
 * @return the field2
 */
@JsonBackReference
public String getField2() {
	return field2;
}
 
源代码28 项目: gwt-jackson   文件: PropertyProcessor.java
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() );
}
 
@JsonBackReference
public SimpleTreeNode2 getParent() {
    return parent;
}
 
@JsonBackReference
public Parent getParent() {
    return parent;
}
 
 同包方法