-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DateTimeSerializerBase
ignores configured date format when creating contextual
#1648
Comments
That sounds like a bug. Would it be possible to create a stand-alone unit test to reproduce the problem? That would help verify the fix, and guard against future regression. |
Yes, this definitely looks like a problem to me; code should not be by-passing contextual default. |
DateTimeSerializerBase
ignores configured date format when creating contextual
@cowtowncoder Maybe I should open another issue, but here is an interesting scenario...
Now suppose I annotate my pojo as follows:
The annotation doesn't change the format but only the timezone - so I expect my custom format will be used. It won't be the case unfortunately: the handling of the annotation is such that it reverts to the format specified on the mapper itself and will bypass my custom module entirely. See what I mean ? |
Hmmh. To be honest, I did not design Now, I am not against trying to make it work (I don't see usage necessarily as wrong), but the better way, in my opinion, is to try to use "config overrides" functionality, added in 2.8, as it allows things like: mapper.configOverride(Date.class)
.setFormat(JsonFormat.Value.forPattern("yyyy.dd.MM")); and is designed to work with default handlers. So... I don't mind your filing a separate issue for using |
I'll try the latter approach. How is you approach different from |
@brenuart Well, use of custom (de)serializers should typically be the last resort, if other approaches are not available or don't work. Config Overrides were added to support equivalent of couple of annotations (specifically Now: as to So, long story short: if setting |
@cowtowncoder Thanks for the very detailed info. For your background, we had to adapt the serialization/deserialization of
Maybe you'll find some of the reasons interesting enough ;-) |
DateTimeSerializerBase#createContextual
creates a new serializer withStdDateFormat.DATE_FORMAT_STR_ISO8601
format instead of re-using the actual format that may have been specified on the configuration. See the following code:Using the
@JsonFormat
annotation on a field will therefore reset the format to Jackson's default even if the annotation doesn't specify any custom format.DateBasedDeserializer#createContextual
behaves differently and tries to re-use the configured format:Shouldn't the serializer follow the same approach ?
The text was updated successfully, but these errors were encountered: