我在Spring上使用API Rest项目.我有一个服务"CreateMateriel",它作为参数数据JSON:
装备对象的JSON
{
"agence": 1,
"code": "001",
"type": "MyType"
}
Run Code Online (Sandbox Code Playgroud)
"物质"与"Agence"有着多对一的关系.我把一个@JsonIdentityInfo标签用来使用Agence的Id而不是Agence的对象(看完这个话题后)
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "idAgence")
@JsonIdentityReference(alwaysAsId = true)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "agence")
private Agence agence;
Run Code Online (Sandbox Code Playgroud)
但是当我在POST/materiels上发送JSON时,我有这个例外:
2017-05-16 18:00:53.021 WARN 8080 --- [nio-8080-exec-8] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Unresolved forward references for:
at [Source: java.io.PushbackInputStream@767dfd7a; line: 5, column: 1]Object id [1] (for fr.app.domain.Agence) at [Source: java.io.PushbackInputStream@767dfd7a; line: 2, column: 14].; nested exception is com.fasterxml.jackson.databind.deser.UnresolvedForwardReference: Unresolved forward …Run Code Online (Sandbox Code Playgroud)