java - SpringBoot : Failing at serialize Integer class

标签 java spring spring-mvc spring-boot

具有 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/

相关文章:

java - 如何通过已经运行的 Java 运行命令?

java - 如何根据 href 链接动态更改 Thymeleaf 片段

spring - 对象引用未保存的 transient 实例 - Spring、JPA Hibernate

java - EL 中的 Spring webflow 完整查询字符串

java - 如何在Spring 3.2.x中修改PathMatch?

java - Tomcat Windows 身份验证 : JNDIRealm doesn't use SPNEGO delegated credentials

java - 具有组计数 gremlin 查询的子句

java - ZK zul 迭代 enummap 以填充网格

servlets - 如何在一个Web应用程序上下文中访问另一个Web应用程序上下文

java - 从 Eclipse Web 项目制作/部署 War 文件