Skip to content

Consistent use of date- and time-related types in endpoint responses #10976

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

Closed
wilkinsona opened this issue Nov 10, 2017 · 6 comments
Closed
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@wilkinsona
Copy link
Member

wilkinsona commented Nov 10, 2017

The endpoints are currently inconsistent in the types that they use for date and time-related types in their responses. For example, the sessions endpoint uses long for creationTime and lastAccessedTime whereas the info endpoint uses a Date for the git info's commit.time and build.time.

An advantage of using a Date is that the format can then be controlled by the user via Jackson's serialisation configuration. An advantage of using a long is that the format doesn't change making it easier to document. Whichever way we go, we should try to make all of the endpoints consistent.

It's worth noting that when consuming a date-like type, the endpoint infrastructure requires the use of ISO 8601 offset date times. Aligning with that (thereby making the formats used in requests and responses consistent) is another option to consider.

@wilkinsona wilkinsona added for: team-attention An issue we'd like other members of the team to review priority: normal type: enhancement A general enhancement labels Nov 10, 2017
@wilkinsona wilkinsona added this to the 2.0.0.RC1 milestone Nov 10, 2017
@vpavic
Copy link
Contributor

vpavic commented Nov 10, 2017

I was just about to open a similar issue, to consider harmonizing the date/time related types between AuditEventEndpoint (which serializes AuditEvent instances) and SessionsEndpoint.

Perhaps it should also be considered to use java.time.Instant (rather than java.util.Date) which is then easily serialized to ISO 8601 UTC representation using SerializationFeature.WRITE_DATES_AS_TIMESTAMPS.

I generally find this set of recommendations useful as a guide for addressing date/time related concerns while building an API.

@wilkinsona wilkinsona removed the for: team-attention An issue we'd like other members of the team to review label Nov 15, 2017
@philwebb
Copy link
Member

We're thinking OffsetDateTime is probably the best option. That should give ISO 8601 output, allow you to always get back to the UTC time but also have the timezone offset should you need it.

@wilkinsona wilkinsona changed the title Consistent use of data- and time-related types in endpoint responses Consistent use of date- and time-related types in endpoint responses Nov 17, 2017
@wilkinsona
Copy link
Member Author

In the interests of being relaxed about what we accept and strict about what we produce, I think the endpoints should consume OffsetDateTime but produce Instant. An Instant would, as @vpavic describes above, be converted to an ISO 8601 representation in UTC. Using Instant would ensure a consistent offset (none) for all timestamps in the responses. If we use OffsetDateTime that consistency could be lost and timestamps may have a variety of offsets.

@wilkinsona
Copy link
Member Author

As part of this, we should ensure that any @JsonFormat annotations are removed (as was proposed in #11588).

@joshiste
Copy link
Contributor

@wilkinsona SessionsEndpoint.SessionDescriptor is still using longs for timestamps...

@wilkinsona
Copy link
Member Author

Thanks for the catch, @joshiste.

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

No branches or pull requests

4 participants