2017-08-13 93 views
1

我在我的項目中使用了spring引導和spring數據,我有兩個類: @Entity public class Mission implements Serializable { private static final long serialVersionUID = 1L;JSON解析錯誤:無法將java.util.ArrayList的實例反序列化爲START_OBJECT標記

@Id 
@GeneratedValue(strategy = GenerationType.IDENTITY) 
private Long    id; 
private String   departure; 
private String   arrival; 
private Boolean   isFreeWayEnabled; 
@OneToMany(mappedBy = "mission") 
private List<Station>  stations; 
// getters and setters 
} 

和第二類是:

@Entity 
public class Station implements Serializable { 

private static final long serialVersionUID = 1L; 

@Id 
@GeneratedValue(strategy = GenerationType.IDENTITY) 
private Long    id; 
private String   station; 

@ManyToOne(fetch = FetchType.LAZY) 
@JsonBackReference 
private Mission   mission; 
//getters and setters 
} 

和控制器:

@RequestMapping(value = "mission/addMission", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8") 
public Reponse addMission(@RequestBody Mission mission) throws ServletException { 
    if (messages != null) { 
     return new Reponse(-1, messages); 
    } 
    boolean flag = false; 
    try { 
     application.addMision(mission); 
     application.addStation(mission.getStations(), mission.getId()); 
     flag = true; 
    } catch (Exception e) { 
     return new Reponse(5, Static.getErreursForException(e)); 
    } 
    return new Reponse(0, flag); 

} 

時i4m嘗試添加一個新的使命probel是,她的JSON對象:

{"departure":"fff","arrival":"ffff","isFreeWayEnabled":false,stations:{"id":1}

+0

你能分享你的json你想反序列化? –

+0

以上:{「出發」:「fff」,「到達」:「ffff」,「isFreeWayEnabled」:false,「站」:{「id」:1} –

回答

1

您正在嘗試反序列化和反對列表,你需要站json陣列

{"departure":"fff","arrival":"ffff","isFreeWayEnabled":false,stations:[{"id":1}, {"id":2}]} 
相關問題