Fork me on GitHub
#ring-swagger
<
2017-08-07
>
rborer13:08:39

Hello everyone, I'm using compojure-api 1.1.11 and I'm trying to understand why a java.util.Date object is not json encoded using the default format (https://github.com/dakrone/cheshire/blob/69a3f2bad66bb9da93d9881266312cd18be4b1a9/src/cheshire/factory.clj#L10) but yyyy-MM-dd'T'HH:mm:SSS'Z' instead. I'm trying to locate where this custom formatter is set but with no luck so far (I checked compojure-api, ring-middleware-format, ring-swagger, ...)

rborer13:08:36

ohh, thanks, didn't thought about checking ring-swagger actually!

juhoteperi13:08:37

java.util.Date is converted to JodaTime DateTime first

rborer13:08:59

ok, so it also means that the switch to muuntaja will not alter this format, correct?

ikitommi13:08:45

But you can override the conversion in your client project

ikitommi13:08:27

Muuntaja will change Cheshire to Jsonista maybe in the future (need to battle test it first), which will bring explicit write-handlers like with Edn & Transit

rborer13:08:44

could the conversion be overridden per endpoint or is it global?

ikitommi13:08:04

but... if you need different format for some endpoints, you can encode the response manually. Just mount a middleware for the route, it sees the coerced response.

rborer13:08:44

make sense actually so I would have more control on the whole format 🙂

ikitommi13:08:15

Write the json by hand / with Jackson / somehow and set the content type & tip for c-api not to encode it.

ikitommi13:08:26

can't recall how, might just be enough if the content-type is set.

rborer13:08:10

thanks a lot for your help!