-
Notifications
You must be signed in to change notification settings - Fork 96
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
NPE when serializing a Timestamp field with custom date-time formatter #577
base: master
Are you sure you want to change the base?
NPE when serializing a Timestamp field with custom date-time formatter #577
Conversation
5c90000
to
fc0a724
Compare
Sorry about a tab character that failed the prebuild checks; replaced it with whitespaces now. |
Hi @greek1979 , thank you for providing this patch :-) May I ask you please to also include test, so we can prevent regression? |
fc0a724
to
5d68bfa
Compare
TL;DR: unit test added. @Verdent , thank you for pointing this out! Writing a simple test case proved to be an enlightening experience, in fact. As I discovered that an |
5d68bfa
to
3e482ef
Compare
12d9fac
to
dbf3e58
Compare
Rebased feature branch from master to fix all the copyright errors that Checkstyle complained about yesterday... |
dbf3e58
to
e36b2b1
Compare
d1aa9e3
to
cb7093e
Compare
Updated this old pull request so the copyright year would comply with Checkstyle strict requirements... |
While working on an unrelated project, I found an issue in Yasson when trying to serialize a POJO with a SQL Timestamp field with a custom date-time formatter enabled in Yasson configuration. The default formatters works just fine, but any explicitly specified formatter produces an NPE in
SqlTimestampSerializer::formatWithFormatter
method as it callsAbstractDateSerializer::toTemporalAccessor
method which simply casts its argument to aTemporalAccessor
. This does not work with legacy java.sql.Timestamp object, however, as Timestamp does not implement a TemporalAccessor read-only interface.Here is a small patch to the
SqlTimestampSerializer
class to convert a Timestamp into aLocalDateTime
(Java 8 Date API) as both hold the same moment-in-time value, UTC time zone, so no information loss occurs. Resulting temporal field cannot be still serialized to JSON with a custom date-time format that includes unsupported elements such as time zone, for example, as neither SQLTimestamp
norLocaDateTime
contain any time zone information. This is expected and is by design (of a rather messyjava.sql.Timestamp
class).