@Test void should_serialize_instant_as_string() throws IOException { var expected = "20190101123456789"; var input = Instant.parse("2019-01-01T12:34:56.789Z"); given(converter.convert(input)).willReturn(expected); serializer.serialize(input, gen, provider); verify(converter).convert(input); verify(gen).writeString(expected); }
@Override public void serialize(Instant instant, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException { try { if (instant == null) { gen.writeNull(); } else { gen.writeString(converter.convert(instant)); } } catch (Exception e) { throw new JsonGenerationException("Could not serialize instant: " + instant, e, gen); } }
InstantSerializer extends StdSerializer<Instant> { @Override public void serialize(Instant instant, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException { try { if (instant == null) { gen.writeNull(); } else { gen.writeString(converter.convert(instant)); } } catch (Exception e) { throw new JsonGenerationException("Could not serialize instant: " + instant, e, gen); } } }
InstantSerializer extends StdSerializer<Instant> { @Override public void serialize(Instant instant, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException { try { if (instant == null) { gen.writeNull(); } else { gen.writeString(converter.convert(instant)); } } catch (Exception e) { throw new JsonGenerationException("Could not serialize instant: " + instant, e, gen); } } InstantSerializer(Converter<Instant, String> converter); }
InstantSerializer extends StdSerializer<Instant> { @Override public void serialize(Instant instant, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException { try { if (instant == null) { gen.writeNull(); } else { gen.writeString(converter.convert(instant)); } } catch (Exception e) { throw new JsonGenerationException("Could not serialize instant: " + instant, e, gen); } } InstantSerializer(Converter<Instant, String> converter); @Override void serialize(Instant instant, JsonGenerator gen, SerializerProvider serializerProvider); }
InstantSerializer extends StdSerializer<Instant> { @Override public void serialize(Instant instant, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException { try { if (instant == null) { gen.writeNull(); } else { gen.writeString(converter.convert(instant)); } } catch (Exception e) { throw new JsonGenerationException("Could not serialize instant: " + instant, e, gen); } } InstantSerializer(Converter<Instant, String> converter); @Override void serialize(Instant instant, JsonGenerator gen, SerializerProvider serializerProvider);  }