jjwt icon indicating copy to clipboard operation
jjwt copied to clipboard

Java8 Date/Time formats

Open petekaras opened this issue 7 years ago • 13 comments

Hi, Maybe I'm missing something so apologies if this is not an issue. I've configured my spring boot application to use jackson-datatype-jsr310 by including in pom.xml, all outgoing json is serialized correctly. however I am using a hashmap to set the payload of the the jwt token:

hashMap.put(Claims.ISSUED_AT,LocalDateTime.now);

and this is being serialized in the Long LocalDateTimeFormat:

{"hour":9,"minute":53,"second":49,"nano":288000000,"dayOfYear":193,"dayOfWeek":"WEDNESDAY","month":"JULY","dayOfMonth":12,"year":2017,"monthValue":7,"chronology":{"calendarType":"iso8601","id":"ISO"}

I had a similar issue in another spring boot application where I was using new ObjectMapper() and not using springBoots configured ObjectMapper. Any ideas how I could make jjwt pick up springboots ObjectMapper which would be configured correctly ? I'm using using jjwt version 0.7.0.

Thanks in advance for your help, Peter

petekaras avatar Jul 12 '17 08:07 petekaras

Unfortunately you cannot currently specify the ObjectMapper that the JwtBuilder will use to generate the resulting JSON. Yet. :)

We'll use this issue to track the work to allow you to do so :)

That said, would you say this issue should be classified as "Allow me to set my own ObjectMapper" ?

Or is the issue really "Please support Java8 Date/Time formats ?

Thoughts?

Thanks for the issue!

lhazlewood avatar Oct 11 '17 23:10 lhazlewood

Hi Les, Yes, I think this is really about supporting Java8 formats. I would be happy to contribute to this project, but am short of time right now. Will let you know if I can help out in the future if you are looking for contributors ?

petekaras avatar Oct 22 '17 18:10 petekaras

It would be nice to have overloaded methods e.g. in Claims e.g.

public Claims setExpiration(LocalDateTime date);
public Claims setNotBefore(LocalDateTime date);
public Claims setIssuedAt(LocalDateTime date);

Would you accept a PR for that?

simdevmon avatar Apr 19 '18 07:04 simdevmon

Depends on #308.

lhazlewood avatar Jul 11 '18 22:07 lhazlewood

This ticket would add support for claims of type:

Anything else?

lhazlewood avatar Jul 11 '18 22:07 lhazlewood

Can we add OffsetDateTime to the list?

cassiomolin avatar May 17 '19 13:05 cassiomolin

I would not support LocalDateTime. LocalDateTime is not an instant and therefore does not identify a point in time. You would need a time zone for that. Which means you don't know how much time has passed since a claim was issued which means that you don't know whether it is expired.

Even the JSR-310 expert group leader thinks LocalDateTime is not generally useful. https://github.com/tc39/proposal-temporal/issues/7#issuecomment-288997620

marschall avatar Aug 06 '19 13:08 marschall

@marschall I completely agree. LocalDateTime is ambiguous. However, Instant has far too many advantages over java.util.Date. I will check other tickets for progress on of deprecation of java.util.Date.

RockyMM avatar Jan 04 '20 22:01 RockyMM

@RockyMM sure, Instant, OffsetDateTime and ZonedDateTime are a great addition and completely fine.

marschall avatar Jan 05 '20 18:01 marschall

Hi, it's 2023, any good news?

imhansai avatar Apr 19 '23 09:04 imhansai

Once #279 is in, Java8 support is next!

bdemers avatar Apr 19 '23 15:04 bdemers

What's the status of this issue?

bartsopers avatar Dec 21 '23 09:12 bartsopers

@bartsopers Not yet implemented, but it will be, likely after the holidays. All of our energy was focused on 0.12.0, so now that it's out, we will focus on other 1.0 issues (like this one) soon.

lhazlewood avatar Dec 21 '23 13:12 lhazlewood