我处于从 type 转换为 type 的场景A
中B
。TypeA
有一个 date 字段,它是 type YearMonth
,而 typeB
的 date 字段是 a String
。我不想重新发明轮子,所以如果我可以使用 Jackson DataType JSR310 库进行此转换,那就太好了。
但是,我很困惑如何以独立的方式使用YearMonthSerializer
's publicserialize
方法;YearMonthDeserializer
的公共deserialize
方法也是如此。
serialize
接受 a YearMonth
(fine) 旁边的 a JsonGenerator
and SerializationProvider
(what?) 我不知道如何检索它,而derialize
甚至没有 aString
作为参数,只有 a JsonParser
and DeserializationContext
。
我不想以典型的方式使用这个库,@JsonSerialize(using = YearMonthSerializer.class)
因为我没有将整个 POJO 转换为 JSON 字符串,只是将一个YearMonth
字段转换为String
.
基于这些 API,尽管看起来我绝对不打算以这种期望的方式使用该库。
这是 javadoc 的链接。