Support Java 8 Datetime in Requests
See original GitHub issueDescribe the problem you’d like to have solved
At the moment, when we try to set a custom List to a user’s user_metadata that contains Objects with a Java 8 Date (an Instant in this case), we get the following error message:
com.auth0.exception.Auth0Exception: Couldn't create the request body.
at com.auth0.net.ExtendedBaseRequest.createRequest(ExtendedBaseRequest.java:51)
at com.auth0.net.BaseRequest.execute(BaseRequest.java:33)
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.Instant` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: com.auth0.json.mgmt.users.User["user_metadata"]->java.util.LinkedHashMap["consents"]->java.util.LinkedList[0]->com.claas.id.backend.backendservice.model.user.Consent["created_at"])
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77)
at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1300)
We use Spring Boot and have a @Bean declared in our Project with an ObjectMapper that has the JavaTimeModule registered. When using this Bean, the conversion works without problems. But it looks like this library internally instantiates a separate ObjectMapper without module registration which causes this error. If I’m doing something wrong, please correct me
Describe the ideal solution
The ideal solution would be that the Auth0 ObjectMapper searches for Modules:
new ObjectMapper()..findAndRegisterModules();
Alternatives and current work-arounds
Currently, we don’t have a work-around other than not using Java 8 Time formats
Additional information, if any
Issue Analytics
- State:
- Created a year ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Enabling Java8 DateTime API support in SpringBoot breaks ...
I have a requirement to accept LocalDate in Spring @PathVariable and also to return LocalDate and LocalDateTime as TimeStamps in Response ...
Read more >Java SE 8 Date and Time - Oracle
The first classes you will probably encounter when using the new API are LocalDate and LocalTime . They are local in the sense...
Read more >New Date-Time API in Java 8 - GeeksforGeeks
New date-time API is introduced in Java 8 to overcome the following drawbacks of old date-time API : Not thread safe : Unlike...
Read more >Rest Controller — Configure Date & Time Format for Request ...
Get Started with Spring - Working with Java 8 Date and Time format pattern for request parameters for in RestController.
Read more >Java 8 - New Date/Time API - Tutorialspoint
LocalDate/LocalTime and LocalDateTime classes simplify the development where timezones are not required. Let's see them in action. Create the following java ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi @larsf96, I was checking out this issue and unfortunately the SDK doesn’t have the ability to do the customization you require.
Ideally, the CustomRequest being extensible should provide an instance of the
bodywhich should be customized in thecreateRequestBody. But currently, we are not exposing an instance of thebodywhere you can do this.A better way is to provide a lambda parameter with an instance of the body where you can customize it. This way you wouldn’t need to extend a class unnecessarily.
I am thinking of a syntax like this
I am going to leave this out here to gather some feedback from others and also from my team. If all good, we can integrate this as a solution.
I think enabling richer customization of requests is something we should look into adding, most likely in v2 so we can consider simplifying the request building. Support for java 8 datetime formats is also something we should add in v2.