具有 Integer 属性的类的对象列表的序列化存在问题。
异常(exception)情况是:
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
}
我检查了对象和学科列表,只是整数属性不为空。
最佳答案
您可以使用以下命令告诉 jackson 忽略它们:
@JsonIgnoreProperties
在你的类(class)
或者单独在每个字段的 getter 处出现此错误
@JsonIgnore
关于java - SpringBoot : Failing at serialize Integer class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37890623/