@Test void should_deserialize_string_as_instant() throws IOException { var input = "20190101123456789"; var expected = Instant.parse("2019-01-01T12:34:56.789Z"); given(parser.readValueAs(String.class)).willReturn(input); given(converter.convert(input)).willReturn(expected); var actual = deserializer.deserialize(parser, ctx); assertThat(actual).isEqualTo(expected); verify(parser).readValueAs(String.class); verify(converter).convert(input); }
@Override public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { try { String text = p.readValueAs(String.class); return text == null ? null : converter.convert(text); } catch (Exception e) { throw new JsonParseException(p, "Could not parse node as instant", e); } }
InstantDeserializer extends StdScalarDeserializer<Instant> { @Override public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { try { String text = p.readValueAs(String.class); return text == null ? null : converter.convert(text); } catch (Exception e) { throw new JsonParseException(p, "Could not parse node as instant", e); } } }
InstantDeserializer extends StdScalarDeserializer<Instant> { @Override public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { try { String text = p.readValueAs(String.class); return text == null ? null : converter.convert(text); } catch (Exception e) { throw new JsonParseException(p, "Could not parse node as instant", e); } } InstantDeserializer(Converter<String, Instant> converter); }
InstantDeserializer extends StdScalarDeserializer<Instant> { @Override public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { try { String text = p.readValueAs(String.class); return text == null ? null : converter.convert(text); } catch (Exception e) { throw new JsonParseException(p, "Could not parse node as instant", e); } } InstantDeserializer(Converter<String, Instant> converter); @Override Instant deserialize(JsonParser p, DeserializationContext ctxt); }
InstantDeserializer extends StdScalarDeserializer<Instant> { @Override public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { try { String text = p.readValueAs(String.class); return text == null ? null : converter.convert(text); } catch (Exception e) { throw new JsonParseException(p, "Could not parse node as instant", e); } } InstantDeserializer(Converter<String, Instant> converter); @Override Instant deserialize(JsonParser p, DeserializationContext ctxt);  }