The request sent by the client was syntactically incorrect Java ZonedDateTime backend
Solution:
Assume you are using the most "default" configuration, which is based on FasterXML Jackson.
If so, then you just need to configure properly serializer and desirializer for ZonedDateTime
in your application; and it might be either custom ones or the ones from jackson-datatype-jsr310 (recommended).
I've created a small/minimal example, which is based on the Spring 5.0.9 and Jackson 2.9.6 (latest versions currently).
Please find it here: spring5-rest-zoneddatetime >>, main parts are:
Event
DTO:public class Event { private long id; private String name; private ZonedDateTime time; // Constructors, public getters and setters }
Field
time
might be apublic
one same to your sample, it is also fine, but if field isprivate
- then you will needpublic
getter and setter.NOTE: I'm ignoring here
@DynamoDBTypeConverted
and@DynamoDBAttribute
annotations since they are related to persistence logic, not the REST layer.EventController
contains only one method same to yours:@RestController public class EventController { @RequestMapping(value = "/event", method = RequestMethod.POST) public ResponseEntity post(@RequestBody Event event) { System.out.println("Event posted: " + event.toString()); return ResponseEntity.ok(event); } }
Dependencies in the
pom.xml
looks so:<dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.0.9.RELEASE</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.6</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-jsr310</artifactId> <version>2.9.6</version> </dependency>
The important one here is JSR-310 datatype implementation, which also introduces
com.fasterxml.jackson.datatype.jsr310.ser.ZonedDateTimeSerializer
andcom.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer
.
Additional information:
In case of custom serializer/desirializer will be needed, please check this question >>
Next date formats will be supported for the
time
field:"2018-01-01T22:25:15+01:00[Europe/Paris]"
- not fully an ISO 8601 btw"2018-01-01T22:25:15+01:00"
"2018-01-01T22:25:15.000000001Z"
1514768461.000000001
- float-pointing number, amount of seconds from the1970-01-01, 00:00:00 [UTC]
By default REST APi response will use float-pointing numbers for dates, e.g. in our case response will look so:
{ "id": 3, "name": "Test event", "time": 1514768460 }
To return string values instead, please check e.g. this question >>
Also need to mention that if you will use Spring Boot instead (good starter) - all things discussed above will work out of the box.