7

Anybody knows how to format LocalTime in Springfox? Converting to ISO format works for LocalDate with this setting to ObjectMapper

.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)

But for LocalTime I'm still getting this in example and model of swagger-ui

"time": {
  "hour": "string",
  "minute": "string",
  "nano": 0,
  "second": "string"
}

I have read something that swagger spec do not use time format. Is this somewhat connected?

Zveratko
  • 2,663
  • 6
  • 35
  • 64

1 Answers1

6

Springfox does not know anything about the serialization features used, nor is there a good way to ask Jackson to figure it out.

However, you can help springfox along by providing model substitution rules. These are basically a way to change the schema of the model that is rendered in the specificiation. In your case a date/time would be represented as a time stamp which is really a long.

So in your Docket you would add a directModelSubstitute to substitute the LocalTime with Long :

docket.directModelSubstitute(LocalTime.class, Long.class)
florian negre
  • 114
  • 1
  • 5
Dilip Krishnan
  • 5,417
  • 3
  • 37
  • 53
  • is there any better way to do this? if one is using Jacksons `LocalTimeSerializer / LocalTimeDeserializer` the long would just throw an exception – Alex Nov 15 '19 at 13:08