Have a java object with a LocalDateTime property that I want to serialize and deserialize with gson. I am using ISO_INSTANT as the format for datetime in the json output
Have tried creating a TypeAdaptor for GSON with the help from this post
But get "Unsupported field: InstantSeconds"
Maybe I have gotten the date conversion messed up?
class LocalDateTimeSerializer implements JsonSerializer<LocalDateTime> {
@Override
public JsonElement serialize(LocalDateTime date, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(
DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.systemDefault()).withLocale(Locale.getDefault()).format(date)); // "yyyy-mm-ddThhMMssZ"
}
}