I have JSONs with a date-time attribute in the format \"2014-03-10T18:46:40.000Z\", which I want to deserialize into a java.time.LocalDateTime field using Gson.
When
To extend @Randula's answer, to parse a zoned date time string (2014-03-10T18:46:40.000Z) to JSON:
Gson gson = new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new JsonDeserializer() {
@Override
public LocalDateTime deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
return ZonedDateTime.parse(json.getAsJsonPrimitive().getAsString()).toLocalDateTime();
}
}).create();