How can I customize date time JSON encoder output?

37 views
Skip to first unread message

Kazuo Koga

unread,
Aug 17, 2019, 12:44:26 PM8/17/19
to Luminus

I created a new app with lein template.

% lein new luminus myapp +reitit +swagger +service 


I would like to customize application/json output string of java-time/offset-date-time object.
default output is "2019-08-18T00:36:03.841+09:00"
and I want to output like "2019/8/18 00:36:03"
How can I?

I found file in template: src/clj/myapp/middleware/formats.clj
but I couldn't get a way.

I'm glad to appreciate any help.
Thank you,

Dmitri

unread,
Sep 10, 2019, 9:26:09 PM9/10/19
to Luminus
Hi,

Sorry for the late reply. The easiest way would be to encode the data as json explictly in the handler using Cheshire, and you could specify a custom encoder for dates that uses the desired format https://github.com/dakrone/cheshire#custom-encoders

You can achieve that using something like (.format (java.text,SimpleDateFormat. "yyyy/M/dd HH:mm:ss") (java.util.Date.))
Reply all
Reply to author
Forward
0 new messages