Udectron
Udectron

Reputation: 59

Strict Date Format Using Jackson and Kotlin

I'm using Jackson, Kotlin and Quarkus and my object mapper registers Java Time Module, Kotlin Module and Serialize feature write dates as timestamps has been disabled

I have a data class that represents my request body, it contains an LocalDate field called creationDate by default the format that I get is yyyy-mm-dd. As the date that come in here is getting used to do a network call, I want to change the format to MM/dd/yyyy to facilitate that

What is the best design that needs to be followed 1.) Get Date in MM/dd/YYYY format and send it ahead ? If so then how can I define a default format for my local date Or 2.) Get default Local Date format from Client and later parse it to MM/dd/yyyy

The main thing that I am having trouble is define a default format for my date field

data class( val createDate: LocalDate, val accountId: Int) // this is my data class for input request

Upvotes: 0

Views: 832

Answers (1)

Anonymous
Anonymous

Reputation: 86130

ISO 8601

The default format that you get, yyyy-mm-dd, is ISO 8601 and is the recommended format for data interchange.

How come you need a different format for your network call, I don’t know. The very best thing would be if you could have that network call changed to accept ISO 8601 format too. Under no circumstances should you let this custom format pollute the JSON that you pass in your request. So second best is to get default date format from client and only format it to MM/dd/yyyy for the network call where this format is required.

Link: ISO 8601 - Wikipedia

Upvotes: 2

Related Questions