2016-06-17 82 views
1

在具有Integer屬性的類的對象列表中存在序列化問題。SpringBoot:在序列化時失敗Integer類

唯一的例外是:

Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: (was java.lang.NullPointerException) (through reference chain: java.util.ArrayList[0]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: java.util.ArrayList[0]) 

類是:Discipline.java

public class Discipline extends AbstractModel { 

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

    private String name; 

    private String course; 

    private Integer teoricLoad; 

    private Integer exerciseLoad; 

    private Integer labLoad; 

    // Ignored getters and setters 
} 

我檢查的對象和學科名單的arent空只是整數屬性。

+0

你怎麼想序列化它們? – jpganz18

+0

@ jpganz18通過控制器映射中的註釋ResponseBody自動序列化。 – Alvadorn

+0

您可以添加更多有關您的問題的細節,但尚不清楚。您是否在使用服務並嘗試撥打它? –

回答

0

你可以告訴傑克遜利用忽略它們:

@JsonIgnoreProperties在你的類

或單獨在各領域的吸氣你有這樣的錯誤與

@JsonIgnore 
+0

但是我希望它在值爲空或只是不在轉換中插入鍵值時寫入「null」字符串,因爲有時候我需要這個屬性。 在另一個模型中,它完成了,但在Discipline模型中它不是,我不知道爲什麼。 – Alvadorn