首页 > 解决方案 > 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 类有很多字段,并且会破坏依赖项的注入。

标签: javaspring

解决方案


推荐阅读