I have a Flutter app that needs to send a post request to my Spring Boot app. The object sent must have a Date in a json string format compatible with the ZonedDateTime java class.
The pattern should be: yyyy-MM-ddTHH:mm[:ss[.S]]ZZ[{ZoneId}]
An example of a date formatted correctly:
{
'date':'2007-12-03T10:15:30+01:00[Europe/Paris]'
}
I'm tried to use time_machine 0.9.9
library at pub.dev, but it doesn't generate the correct pattern. Here is an example:
import 'package:time_machine/time_machine.dart';
Map<String, dynamic> toJson() => <String, dynamic>{
'date': '${Instant.now().inLocalZone()}'
}
Generates:
{
"date":"2019-08-07T22:24:54 UTC (+00)"
}
Spring boot app throws an exception:
org.springframework.messaging.converter.MessageConversionException: Could not read JSON: Cannot deserialize value of type `java.time.ZonedDateTime` from String "2019-08-07T22:24:54 UTC (+00)": Failed to deserialize java.time.ZonedDateTime: (java.time.format.DateTimeParseException) Text '2019-08-07T22:24:54 UTC (+00)' could not be parsed at index 19