【发布时间】:2021-01-03 14:53:15
【问题描述】:
杰克逊尝试序列化空即时对象时遇到了一些问题。在我的数据库模型中,我有一些可以为空的时间戳,我希望能够像这样将它们发送给客户端。
问题是,当我生成响应时,我总是看到这些错误:
Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: (was java.lang.NullPointerException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain:...
通过调试 y 显示该字段是 Instant。这是有问题的吸气剂...
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public Instant getStartTime() {
return startTime.toInstant();
}
我尝试对字段、getter 和整个类使用 @JsonInclude 注释,但我仍然收到该消息和客户端上的 500。
我正在使用包含 jackson 2.11.0 的 Spring-boot。
非常感谢
【问题讨论】:
标签: java json spring-boot serialization jackson