Comments (6)
@cowtowncoder The local timezone may not be important, but take this case:
Web application, a particular date is saved as LocalDate because it actually does not care about time zone.
The user being in GMT+2 zone, picks Apr 30th 2020, so he'll expect to see Apr 30th 2020 back, however, he sees Apr 29th 2020.
How:
The user chose Apr 30th 2020, he is in GMT+2.
Since it is a date object, javascript sends it as "2020-04-29T22:00:00.000Z"
In backend they expect a LocalDate so Jackson translates that string. Since it does not care about the locale of the user, the date becomes Apr 29th 2020.
So while the server's locale should not be used, the locale of the request should.
And btw, this is a real case in the application I work in right now
from jackson-modules-java8.
I am not sure why you think local timezone should be used for anything -- Jackson does not use it for anything by default, due to fundamental fragility of relying on something that essentially varies arbitrarily. Instead, default timezone is UTC.
But you can change that easily enough if you want to.
Further, LocalDate
does NOT mean it is in local timezone or such, but rather that date/time value is independent of timezone and essentially has not meaning without being bound to specific timezone. Name may be seen bit misleading by Javadocs explains it:
https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html
So, I do not see behaviour here as wrong -- especially since use of date.toString()
for printing out itself tells very little about actual value -- it may use whatever formatting and timezone settings you happen to have.
from jackson-modules-java8.
Thank you for your time and your explanation. I assumed LocalDate represents a date in the local time zone and not a date without time zone.
from jackson-modules-java8.
@pherklotz Yes, I can see how name would imply that. Naming is hard, and I am not quite sure why Java 8 name was chosen this way.
from jackson-modules-java8.
@dariotortola I think the issue you mention might be fixed/addressed with #94
from jackson-modules-java8.
@kupci I'm afraid not - the scenario described by dariotortola is not handled by #94 - I just updated jackson to newest version in the hope it would be, but the fix of #94 is:
if (string.endsWith("Z")) {
if (isLenient()) {
return LocalDateTime.parse(string.substring(0, string.length()-1),
_formatter);
}
So this basically means: cut off the Z and parse it as "2020-04-29T22:00:00.000".
Also if this string should be parsed as LocalDate (without Time) the code goes like this with the same result:
return string.endsWith("Z") ? LocalDateTime.ofInstant(Instant.parse(string), ZoneOffset.UTC).toLocalDate() : ...;
So long story short: I think you must tell your client somehow not to convert the "2020-04-30" into a "2020-04-29T22:00:00.000Z" when sending it to the server.
If I am mistaken somewhere and there actually is a way to configure jackson to make a "2020-04-29T22:00:00Z" into "200-04-30"-LocalDate, please tell me! It would be very helpful!
from jackson-modules-java8.
Related Issues (20)
- Milliseconds timestamps not parsing correctly for `LocalDate` even with `READ_DATE_TIMESTAMPS_AS_NANOSECONDS` as FALSE HOT 8
- Breaking change in `InstantDeserializer API between 2.15 and 2.16 HOT 1
- `LocalDateTime` serialization issue with custom-configured `LocalDateTimeSerializer` HOT 12
- InstantDeserializer fails to parse negative numeric timestamp strings for pre-1970 values. HOT 2
- Custom java time module ignored after upgrade to 2.16 HOT 3
- `Optional` deserialization, serialization ignore `contentConverter` HOT 1
- NPE when serializing a `LocalDate` or `LocalDateTime` using `AsDeductionTypeSerializer` HOT 9
- OffsetTimeSerializer not writing seconds for time object like 15:30:00Z (where seconds is 00) HOT 2
- Implicit name provided by `ParameterNamesModule` overridden by "incomplete" `@JsonProperty` HOT 1
- I don't deserialize java 8 date/time type `java.time.Instant` HOT 2
- ZonedDateTime not serialised as UTC by default HOT 1
- Instants get not deserialized as expected sometimes HOT 2
- Only `DateTimeFormatter.ISO_OFFSET_DATE_TIME` accepted by `ZonedDateTimeKeyDeserializer` HOT 1
- Can't deserialize OffsetDateTime.MIN: Invalid value for EpochDay
- Date and time serialization are very inconsistent HOT 3
- Absent nested optional shennanigans HOT 1
- The serialization of an object of type LocalDate did not record its type HOT 2
- Q on Serializing java.time dates w/o nano parts HOT 2
- Add javaTimeModule.addDeserializer(String.class,...) Error parsing generated later HOT 4
- java.lang.NoSuchFieldError: READ_DATE_TIMESTAMPS_AS_NANOSECONDS after update to 2.16 or 2.17 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jackson-modules-java8.