我的用户和权限类相关如下
public class User {
@JsonIgnoreProperties(value = "users", allowSetters = true)
@ManyToMany(fetch = FetchType.EAGER) //To avoid MultipleBagFetchException
@Fetch(value = FetchMode.SUBSELECT)
@LazyCollection(LazyCollectionOption.FALSE)
@JoinTable(
name = "USER_AUTHORITY",
joinColumns = {@JoinColumn(name = "USER_ID", referencedColumnName = "USER_ID")},
inverseJoinColumns = {@JoinColumn(name = "AUTHORITY_ID", referencedColumnName = "ID")})
private List<Authority> authorities = new ArrayList<Authority>();
}
public class Authority {
@JsonIgnoreProperties(value = "authorities", allowSetters = true)
@ManyToMany(mappedBy = "authorities", fetch = FetchType.LAZY)
private List<User> users = new ArrayList<User>();
}
更新用户给我以下错误
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot invoke "com.fasterxml.jackson.databind.JsonDeserializer.getObjectIdReader()" because "valueDes" is null; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Cannot invoke "com.fasterxml.jackson.databind.JsonDeserializer.getObjectIdReader()" because "valueDes" is null (through reference chain: com.siraafalagi.siraAfalagi.model.User["jobApplications"]->java.util.ArrayList[0]->com.siraafalagi.siraAfalagi.model.JobApplication["jobSeekers"]->java.util.ArrayList[0]->com.siraafalagi.siraAfalagi.model.JobSeeker["jobSeekerAddingUser"]->com.siraafalagi.siraAfalagi.model.User["authorities"])
Caused by: java.lang.NullPointerException: Cannot invoke "com.fasterxml.jackson.databind.JsonDeserializer.getObjectIdReader()" because "valueDes" is null
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:276) ~[jackson-databind-2.11.4.jar:2.11.4]
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:249) ~[jackson-databind-2.11.4.jar:2.11.4]
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:26) ~[jackson-databind-2.11.4.jar:2.11.4]
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129) ~[jackson-databind-2.11.4.jar:2.11.4]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:371) ~[jackson-databind-2.11.4.jar:2.11.4]
... 124 common frames omitted
我看到了一个未解决的问题 here。解决此问题的方法是什么?
答案 0 :(得分:0)
就我而言,使用注释在所有级联类的 allowSetters = true
上添加 @JsonIgnoreProperties
有助于解决此问题。