Java REST将许多邮件发送回服务器

Java REST将许多邮件发送回服务器,java,spring,rest,spring-boot,Java,Spring,Rest,Spring Boot,我有一个@manytomy和一个@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class) 如果我将对象发回,我会得到: error: "Bad Request" exception: "org.springframework.http.converter.HttpMessageNotReadableException" message: "Could not read document: No _valu

我有一个
@manytomy
和一个
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class)

如果我将对象发回,我会得到:

error: "Bad Request"
exception: "org.springframework.http.converter.HttpMessageNotReadableException"
message: "Could not read document: No _valueDeserializer assigned↵ at [Source: java.io.PushbackInputStream@3021b8dc; line: 1, column: 244] (through reference chain: at.scool.model.db.Teacher["classes"]->java.util.HashSet[0]->at.scool.model.db.SchoolClass["teachers"]->java.util.HashSet[0]->at.scool.model.db.Teacher["id"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No _valueDeserializer assigned↵ at [Source: java.io.PushbackInputStream@3021b8dc; line: 1, column: 244] (through reference chain: at.scool.model.db.Teacher["classes"]->java.util.HashSet[0]->at.scool.model.db.SchoolClass["teachers"]->java.util.HashSet[0]->at.scool.model.db.Teacher["id"])"
path: "/api/teacher/1"
status: 400
timestamp: 1446921619542
源代码

老师

@ManyToMany
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
private Set<SchoolClass> classes = new HashSet<>();
@manytomy
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class,property=“id”)
私有集合类=新HashSet();
学校班级

@ManyToMany
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
private Set<Teacher> teachers = new HashSet<>();
@manytomy
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class,property=“id”)
私有集教师=新HashSet();
@zt1983811
是的,我找到了一个解决方案,但我忘了在这里发布
原因之一:我不认为这是“很好”的编程,但现在我们开始:

回答

@ManyToMany
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
private Set<SchoolClass> classes = new HashSet<>();
一个类需要顶部的
@JsonIdentityInfo

@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class)
public class Teacher {
// ...
@ManyToOne(optional = false)
@JsonBackReference(value = "teachers")
private School school;
另一个在变量处需要它:

@ManyToMany
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class)
private Set<Teacher> teachers = new HashSet<>();
@manytomy
@JsonIdentityInfo(生成器=ObjectedGenerators.IntSequenceGenerator.class)
私有集教师=新HashSet();

你确定你的语法正确吗?更新了我的帖子code@rala你找到解决办法了吗?