jwtk / jjwt

Java JWT: JSON Web Token for Java and Android
Apache License 2.0
10.32k stars 1.34k forks source link

Java8 Date/Time formats #235

Open petekaras opened 7 years ago

petekaras commented 7 years ago

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

lhazlewood commented 7 years ago

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!

petekaras commented 7 years ago

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 ?

simdevmon commented 6 years ago

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?

lhazlewood commented 6 years ago

Depends on #308.

lhazlewood commented 6 years ago

This ticket would add support for claims of type:

Anything else?

cassiomolin commented 5 years ago

Can we add OffsetDateTime to the list?

marschall commented 5 years ago

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

RockyMM commented 4 years ago

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

marschall commented 4 years ago

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

imhansai commented 1 year ago

Hi, it's 2023, any good news?

bdemers commented 1 year ago

Once #279 is in, Java8 support is next!

bartsopers commented 10 months ago

What's the status of this issue?

lhazlewood commented 10 months ago

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