My Json looks like following
{
name: "math",
code:null,
description:"Mathematics",
id:null,
name:"math",
noExam:null,
teacher:{
id: "57869ced78aa7da0d2ed2d92",
courseGroup:"LKG",
experties:[{type: "SOCIALSTUDIES", id: "3"}, {type: "PHYSICS", id: "4"}]
},
id:"57869ced78aa7da0d2ed2d92"
}
if you see my entity classes, I have a set of enums in Teacher.java
When I try to post this I get error
JsonMappingException: Can not deserialize instance of com.iris.fruits.domain.enumeration.Experties out of START_OBJECT token
I have tried almost all solutions out there, like DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY
, but without success.
public class Subject implements Serializable {
// all the other fields
@JoinColumn(name = "teacher_id")
private Teacher teacher;
// getter and setter
}
public class Teacher implements Serializable {
// all the other fields
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private String id;
@Enumerated(EnumType.STRING)
@Column(name = "experties")
@JsonProperty("experties")
private List< Experties> experties;
// getter and setter
}
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum Experties implements Serializable {
MATH(1,"MATH"),
SCIENCE(2,"SCIENCE"),
SOCIALSTUDIES(3,"SOCIALSTUDIES"),
PHYSICS(4,"PHYSICS"),
CHEMISTRY(5,"CHEMISTRY");
@JsonSerialize(using = ToStringSerializer.class)
private String type;
@JsonSerialize(using = ToStringSerializer.class)
private Integer id;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
Experties(Integer id, final String type) {
this.id = id;
this.type = type;
}
}