SpringBoot:序列化整数类失败

时间:2016-06-17 21:28:40

标签: java spring spring-mvc spring-boot

在具有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
}

我检查了对象,并且学科列表只是整数属性。

1 个答案:

答案 0 :(得分:0)

您可以通过使用以下方式告诉杰克逊忽略它们:

你班上的

@JsonIgnoreProperties

或单独在每个字段的getter处出现此错误

@JsonIgnore