java - Jackson 无法将 String 转换为 OffsetDateTime
问题描述
我有一堂课,比如
import java.time.OffsetDateTime;
public class AState {
AName name;
String message;
OffsetDateTime updatedAt;
public AssetStatusState() {
}
}
//getters and setters follow
在我的项目中作为 Maven 依赖项导入。在我的项目中,我从事件总线接收到一个 JSON 字符串,并尝试将其解析为一个类型为 的对象AState
。JSON 字符串的格式为:
{"name":"comps", "message":"ok", "updatedAt":"2020-03-05T02:31:17.683Z"}
我尝试通过以下方式解析:
this.objectMapper.convertValue(someString, AState.class)
当我构建我的主要对象时,我也会这样做
this.objectMapper.register(new JavaTimeModule());
但我仍然无法解决这个错误 - 我不知道我做错了什么,有人可以帮忙吗?
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException:
Cannot construct instance of `java.time.OffsetDateTime`
(no Creators, like default construct, exist): no String-argument constructor/factory method
to deserialize from String value ('2020-03-05T02:31:17.683Z')
at [Source: UNKNOWN; line: -1, column: -1]
然而,在独立测试中,反序列化就像一个魅力。JSON字符串有问题吗?
解决方案
推荐阅读
- python - seaborn boxplot 和 stripplot 点未按色调在 x 轴上对齐
- sql - 无法使用 After Insert 触发器获取计算值
- python - Python。提取 rar 文件时出现类型错误:“NoneType”对象不可迭代
- python - 将子目录中的导入分组在一起
- python - python sqlite代码有效,但我得到一些错误
- deno - 如何让 Deno 使用 DENO_AUTH_TOKENS 环境变量?
- ios - 如何在 react-native 中修复“尝试删除比添加更多的 RCTLinkingManager 侦听器”
- http - 如何强制sails js csrf或登录路由始终设置响应标头set-cookie
- javascript - 如何在 .json 或 .js 文件上使用 react-i18-next?
- html - 知道为什么我的本地网站/视觉工作室预览显示网站与实际现场网站不同吗?