Cannot construct instance of `java.time.ZonedDateTime` (no Creators, like default construct, exist)
As @PaulSamsotha pointed out, I need to register the JacksonJsonProvider on the client side too:
ClientConfig cc = new DefaultClientConfig();
cc.getSingletons().add(ShopApplication.newJacksonJsonProvider());
wr = Client.create(cc).resource(Main.BASE_URI.resolve("products"));
which contains the customized solution:
private static JacksonJsonProvider newJacksonJsonProvider() {
ObjectMapper mapper =
new ObjectMapper()
.registerModule(new ParameterNamesModule())
.registerModule(new Jdk8Module())
.registerModule(new JavaTimeModule()); // new module, NOT JSR310Module
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.setDateFormat(new StdDateFormat());
return new JacksonJsonProvider(mapper);
}
I was able to deserialize a JSON file with a ZonedDateTime with this code.
ObjectMapper objectMapper = new ObjectMapper()
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
objectMapper.registerModule(new JavaTimeModule())
MyObject myObject = objectMapper.readValue(new File("src/test/resources/data/my_object.json"), MyObject.class)