gpt4 book ai didi

java - SpringBoot : Failing at serialize Integer class

转载 作者:太空宇宙 更新时间:2023-11-04 12:30:34 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com