I'm in a scenario where I'm converting from type A
to type B
. Type A
has a date field which is of type YearMonth
, and type B
's date field is a String
. I don't want to reinvent the wheel, so it'd be great if I could use The Jackson DataType JSR310 library for this conversion.
However, I'm quite confused how I can use the YearMonthSerializer
's public serialize
method in a standalone way; same goes for YearMonthDeserializer
's public deserialize
method.
serialize
takes in a YearMonth
(fine) alonside a JsonGenerator
and SerializationProvider
(what?) which I'm not sure how to retrieve, whereas derialize
doesn't even have a String
as an argument, just a JsonParser
and DeserializationContext
.
I don't want to use this library in the typical way @JsonSerialize(using = YearMonthSerializer.class)
because I'm not converting an entire POJO to a JSON sting, just one YearMonth
field to a String
.
Based on these APIs though it almost looks like I am definitely not intended to use the library in this desired way.
Here 'sa link to the javadoc.
why not you use the @JsonSerialize(using = YearMonthSerializer.class)
above the date field instead of above the class. because you don't want to use it for the entire POJO
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.