Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DateTimeFormatter for javatime codecs #768

Merged
merged 2 commits into from
Sep 30, 2020

Conversation

johnspade
Copy link
Contributor

Javatime codecs should serialize dates and times with formats that are used to parse them.
Tapir uses OffsetDateTime's .toString to encode Instants, but you can't parse back some of its outputs:

import java.time.Instant
import sttp.tapir.Codec.instant

val epoch = instant.encode(Instant.EPOCH)
// epoch: String = 1970-01-01T00:00Z
Instant.parse(epoch)
// java.time.format.DateTimeParseException: Text '1970-01-01T00:00Z' could not be parsed at index 16

I think it's better to be more explicit about formats and not to rely on .toString for javatime codecs.

checkEncodeDecodeToString[LocalDate]
checkEncodeDecodeToString[OffsetDateTime]
checkEncodeDecodeToString[Instant]
checkEncodeDecodeToString[ZoneOffset]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about tests for these types? would be good if they are still covered

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added missing tests

@adamw adamw merged commit 4822fc8 into softwaremill:master Sep 30, 2020
@adamw
Copy link
Member

adamw commented Sep 30, 2020

Released in 0.17.0-M2, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants