Code Monkey home page Code Monkey logo

Comments (6)

dariotortola avatar dariotortola commented on July 30, 2024 1

@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.

cowtowncoder avatar cowtowncoder commented on July 30, 2024

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.

pherklotz avatar pherklotz commented on July 30, 2024

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.

cowtowncoder avatar cowtowncoder commented on July 30, 2024

@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.

kupci avatar kupci commented on July 30, 2024

@dariotortola I think the issue you mention might be fixed/addressed with #94

from jackson-modules-java8.

fsomme2s avatar fsomme2s commented on July 30, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.