java - ObjectMapper 反序列化的特定第三方字段
问题描述
我有一个调用 Google API 的软件,我不能使用 Google Libraries 进行调用,但可以使用模型。所以我通过 RestTemplate 调用 Google API。当 RestTemplate 尝试使用 ObjectMapper 反序列化 Google 的 DateTime 对象时,问题就出现了。
Caused by: java.lang.IllegalArgumentException: Can not set com.google.api.client.util.DateTime field com.google.api.services.calendar.model.Events.updated to java.lang.String
所以,我需要修改 ObjectMapper 尝试解码 DateTime 类,objectMapper 调用一个接口,让我有机会手动反序列化。
我尝试使用模块和反序列化器,但它们仅在您将其放在顶级类上或在变量上放置注释时才使用,但我的类是第三方的,因此我无法修改。
我也尝试使用 mixin,但他们必须放置 al 变量,这会花费大量时间,因为 Google 类有很多字段,并且会破坏依赖项的注入。
解决方案
推荐阅读
- asp.net - ASP 页面加载时间设备到设备
- python - 使用 configparser 从配置文件中解析数字和列表
- javascript - ChartJS 和 Flask,如何传递数据?
- android - 导航组件 currentDestination 按下后退按钮后为空
- pandas - 我如何用熊猫数据框中另一行中的值替换一行中的 NaN
- visual-studio - 如何使用 Visual Studio 在真实域上调试应用程序
- regex - 移动到子程序时,PCRE 正则表达式的行为不同
- python - 使用 PySFTP 和 putfo 上传字节
- python-3.x - 我应该使用 matplotlib 中的哪种绘图?
- php - php chilkat_9_5_0 扩展在 Windows 10 中不起作用