Jackson , java.time , ISO 8601 , serialize without milliseconds : <p>I'm using Jackson 2.8 and need to communicate with an API that doesn't allow milliseconds within ISO 8601 timestamps.</p>

<p>The expected format is this: <code>"2016-12-24T00:00:00Z"</code></p>

<p>I'm using Jackson's JavaTimeModule with <code>WRITE_DATES_AS_TIMESTAMPS</code> set to <code>false</code>.</p>

<p>But this will print milliseconds.</p>

<p>So I tried to use <code>objectMapper.setDateFormat</code> which didn't change anything.</p>

<p>My current workaround is this:</p>

<pre><code>ObjectMapper om = new ObjectMapper();

DateTimeFormatter dtf = new DateTimeFormatterBuilder()
    .appendInstant(0)
    .toFormatter();

JavaTimeModule jtm = new JavaTimeModule();
jtm.addSerializer(Instant.class, new JsonSerializer&lt;Instant&gt;() {
    @Override
    public void serialize(Instant value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
        gen.writeString(dtf.format(value));
    }
});

om.registerModule(jtm);
</code></pre>

<p>I'm overriding the default serializer for <code>Instant.class</code> which works.</p>

<hr>

<p>Is there any nice way using some configuration parameter to solve this?</p>
