I been receiving date in the "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" format from JSON input, which gets converted to a DTO by Spring it self. But when converted to OffsetDateTime
instance, this loses the information about Offset in the created OffsetDateTime instance. For example we are passing following in the Postman invoking an API, this results in the parsing and object getting created but the object doesn't have offset set in it.
Below is the example of the "2019-03-21T06:43:56.235+11:00"
date when parsed it results in the date with OffsetDateTime instance but it doesn't have the +11:00
as the offset. When I directly parse this string using DateTimeFormatter
I am able to get the offset populated.
below is the code that uses DateTimeFormatter
.
OffsetDateTime.parse(offSetDateTimeString, DateTimeFormatter.ofPattern(DATE_PATTERN))
The DATE_PATTER = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
.
Please guide.
Thank you.
UPDATE
My DO has following objects:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
// THis won't work as it doesn't support timestamp.
// @Column(columnDefinition = "TIMESTAMP WITH TIME ZONE")
// private LocalDateTime localDateTime;
@Column(columnDefinition = "TIMESTAMP WITH TIME ZONE")
private ZonedDateTime zonedDateTime;
@Column(columnDefinition = "TIMESTAMP WITH TIME ZONE")
private OffsetDateTime offSetDateTime;
While DTO also has same fields with SAME data types.