I fixed this by adding
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class User {
to my User.java class
Answer from Peter Boomsma on Stack Overflowpostgis - Failing to deserialize geometry point data in Spring Boot REST API - Geographic Information Systems Stack Exchange
java - Jackson failed to deserialization OneToMany objects - Stack Overflow
Failed to evaluate Jackson deserialization in spring boot api - Stack Overflow
java - Failed to evaluate Jackson deserialization - Stack Overflow
You could add @JsonBackReference to the other site of the relation. Which by the way is missing or not correct implemented. Add:
@JsonBackReference
@ManyToOne
@JoinColumn(name = "autoServiceId", nullable = false)
private AutoService autoService;
instead of private long autoServiceId;.
Also the AutoService needs to be adjusted with:
@JsonManagedReference
@OneToMany(mappedBy = "autoService", fetch=FetchType.EAGER)
private List<Service> services = new ArrayList<>();
Solution #1 : - add @JsonIgnore where you have attributes with @OneToMany Example:
class User {
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JsonManagedReference
@JsonIgnore
private List<Comment> comments;
}
class Comment {
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "user_id")
@JsonBackReference
private User user;
}
Solution #2: - use on your class @JsonIgnoreProperties({"name-of-your-attribute"}), for example "comments"
You reference the name user-movement more than once in your object tree as @JsonBackReference. You'll need to rename one of them. The two cases are:
@JsonBackReference(value="user-movement")
public Set<Device> getDevice() {
return devices;
}
And
@JsonBackReference(value="user-movement")
public Main_schedule getMain_schedule_schedule_id(){
return main_schedule;
}
See more: Jackson: Multiple back-reference properties with name 'defaultReference'
@JsonBackReference
@OneToMany(fetch=FetchType.LAZY,
mappedBy = "device_group"
cascade=cascadeType.PERSIST)
private Set<Device> devices;
@JsonManagedReference
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="device_group_group_id")
private Device_group device_group;
The proper way to solve this without a default constructor is to add JsonCreator and JsonProperty annotations to your class constructor.
class MyClass {
String name;
@JsonCreator
MyClass(@JsonProperty("name") String name) {
this.name = name;
}
...
}
Jackson uses Getter and Setters to set values. So you need to modify your class:
class MyClass {
String name;
MyClass(String name) {
this.name = name;
}
MyClass(){}
public void setName(String name) {
this.name = name;
}
public String getName(String name) {
return this.name;
}
}