由于我的域类中的关联不明确,新添加LinkCollectingAssociationHandler
的内容会抛出一个。MappingException
链接数组如下所示:
[<http://localhost:8080/rooms/2/roomGroups>;rel="roomGroups", <http://localhost:8080/rooms/2/userGroup>;rel="userGroup", <http://localhost:8080/rooms/2/room>;rel="room", <http://localhost:8080/rooms/2/originatingConferences>;rel="originatingConferences", <http://localhost:8080/rooms/2/user>;rel="user"]
当它抛出异常时,它正试图添加另一个“房间”关系。
问题是它似乎正在添加指向我已明确标记的关系的链接@RestResource(exported = false)
这是我认为导致此问题的关系示例:
@JsonIgnore
@RestResource(exported = false)
@OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.room", cascade = {CascadeType.REMOVE})
private Set<RoomsByUserAccessView> usersThatCanDisplay = new HashSet<>();
该类型有一个由 a和 aRoomsByUserAccessView
组成的嵌入 id 。Room
User
我还注释了嵌入的 id 属性:
@JsonIgnore
@RestResource(exported = false)
private RoomsByUserAccessViewId pk = new RoomsByUserAccessViewId();
及其属性如下:
@JsonIgnore
@RestResource(exported = false)
private Room room;
@JsonIgnore
@RestResource(exported = false)
private User userWithAccess;
public RoomsByUserAccessViewId() {
//
}
在序列化为 JSON 时,如何让它正确地忽略这些关系?
我的代码在 DATAREST-262 之前工作(https://github.com/spring-projects/spring-data-rest/commit/1d53e84cae3d09b09c4b5a9a4caf438701527550)
当我尝试访问 rooms/ 端点时返回的完整错误消息如下:
{
timestamp: "2014-03-17T13:38:05.481-0500"
error: "Internal Server Error"
status: 500
exception: "org.springframework.http.converter.HttpMessageNotWritableException"
message: "Could not write JSON: Detected multiple association links with same relation type! Disambiguate association @com.fasterxml.jackson.annotation.JsonIgnore(value=true) @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 com.renovo.schedulerapi.domain.Room com.renovo.schedulerapi.domain.RoomsByUserAccessViewId.room using @RestResource! (through reference chain: org.springframework.hateoas.PagedResources["content"]->java.util.UnmodifiableCollection[0]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Detected multiple association links with same relation type! Disambiguate association @com.fasterxml.jackson.annotation.JsonIgnore(value=true) @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 com.renovo.schedulerapi.domain.Room com.renovo.schedulerapi.domain.RoomsByUserAccessViewId.room using @RestResource! (through reference chain: org.springframework.hateoas.PagedResources["content"]->java.util.UnmodifiableCollection[0])"
}