@RestResource(exported = false)被忽略

fre*_*man 7 spring json spring-data-rest

在标题中 - 我的@RestResource(exported = false)在字段上被忽略.Spring数据休息仍然想从中创建json,我想暂时跳过它,因为在WorkflowEvent中更改rel没有给我任何东西..

 @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "submission")
@OrderBy("date desc")
@RestResource(exported = false)
private List<WorkflowEvent> events = new ArrayList<WorkflowEvent>();
Run Code Online (Sandbox Code Playgroud)

我明白了:

{"timestamp":1410850806347,"status":500,"error":"Internal Server Error","exception":"org.springframework.http.converter.HttpMessageNotWritableException","message":"Could not write JSON: Detected multiple association links with same relation type! Disambiguate association @javax.persistence.JoinColumn(insertable=true, unique=false, referencedColumnName=, columnDefinition=, name=submission_id, updatable=true, nullable=true, table=, foreignKey=@javax.persistence.ForeignKey(name=, value=CONSTRAINT, foreignKeyDefinition=)) @javax.persistence.ManyToOne(fetch=EAGER, cascade=[], optional=true, targetEntity=void) @org.springframework.data.rest.core.annotation.RestResource(description=@org.springframework.data.rest.core.annotation.Description(value=), path=, exported=false, rel=) private mypackage.MyClass mypackage.WorkflowEvent.myclass using @RestResource!; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Detected multiple association links with same relation*
Run Code Online (Sandbox Code Playgroud)

当我评论这个领域时它是有效的.

我的版本:

\- org.springframework.data:spring-data-rest-webmvc:jar:2.1.4.RELEASE:compile
[INFO] |     \- org.springframework.data:spring-data-rest-core:jar:2.1.4.RELEASE:compile
[INFO] |        +- org.springframework.hateoas:spring-hateoas:jar:0.16.0.RELEASE:compile
Run Code Online (Sandbox Code Playgroud)

Oli*_*ohm 11

@RestResources仅在指向托管资源的域属性上受支持.因此,如果您没有WorkflowEvent通过Spring Data REST托管存储库公开,则注释无论如何都不会产生任何影响.在这种情况下,只需使用一个@JsonIgnore让杰克逊不渲染财产.