Skip to content

Java8 Date/Time formats  #235

Open
@petekaras

Description

@petekaras

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

Activity

lhazlewood

lhazlewood commented on Oct 11, 2017

@lhazlewood
Contributor

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

petekaras commented on Oct 22, 2017

@petekaras
Author

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 ?

changed the title [-]Java8 jsr310 LocalDateTime [/-] [+]Please support Java8 Date/Time formats [/+] on Oct 22, 2017
added this to the 1.0 milestone on Nov 1, 2017
simdevmon

simdevmon commented on Apr 19, 2018

@simdevmon

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?

changed the title [-]Please support Java8 Date/Time formats [/-] [+]Java8 Date/Time formats [/+] on Jul 11, 2018
lhazlewood

lhazlewood commented on Jul 11, 2018

@lhazlewood
Contributor

Depends on #308.

lhazlewood

lhazlewood commented on Jul 11, 2018

@lhazlewood
Contributor

This ticket would add support for claims of type:

Anything else?

cassiomolin

cassiomolin commented on May 17, 2019

@cassiomolin

Can we add OffsetDateTime to the list?

marschall

marschall commented on Aug 6, 2019

@marschall

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.
tc39/proposal-temporal#7 (comment)

RockyMM

RockyMM commented on Jan 4, 2020

@RockyMM

@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

marschall commented on Jan 5, 2020

@marschall

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

imhansai

imhansai commented on Apr 19, 2023

@imhansai

Hi, it's 2023, any good news?

14 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    jdk8Changes related to migrating to JDK8 API features

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      Participants

      @bdemers@lhazlewood@marschall@RockyMM@cassiomolin

      Issue actions

        Java8 Date/Time formats · Issue #235 · jwtk/jjwt