in Education by
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. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Okay, here is what I did to solve this issue. Instead of accepting OffsetDateTime in DTO, I accepted String. For this I required changes to be done in the Mapper (MapStruct). I defined custom String to OffsetDateTime mapper classes and specified them in the uses in @Mapper. This solved my parsing related issue, then moving on to the DB, I noticed a couple of things. TIMESTAMP WITH TIME ZONE doesn't store the date in the exact given format. You need to use the ZoneId to convert the time to appropriate timezone. And you have to write custom Utility for this kind of conversion. We need to obtain now the relevant timezone's zoneId object, which we have currently obtained from the incoming request. This is the update as of now. Posting this for other's reference. Thank you all for guiding.

Related questions

0 votes
    I have a data which looks like EX:992215:SHOW:CMS016:000335:ESP:15:EUR:Euro:4:14:01/05/2009 :30 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: converting date format (5 answers) Closed 5 years ago. I have a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I have a data which looks like EX:992215:SHOW:CMS016:000335:ESP:15:EUR:Euro:4:14:01/05/2009 :30 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I have a data which looks like EX:992215:SHOW:CMS016:000335:ESP:15:EUR:Euro:4:14:01/05/2009 :30 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    What will be the syntax to find current date and time in format "YYYY-MM-DD"?...
asked Dec 18, 2020 in Technology by JackTerrance
0 votes
    How to format a Microsoft JSON date?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    I am getting Facebook users' friends birthday back from Facebook in the following format: 10/07/1967 or ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 21, 2022 in Education by JackTerrance
0 votes
    I am getting Facebook users' friends birthday back from Facebook in the following format: 10/07/1967 or ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 21, 2022 in Education by JackTerrance
0 votes
    here is my code. var http=require("http"); var fs = require("fs"); var express = require(" ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    How do I parse a string eg. "01/21 - 02/20" which is represented as month/day to month/day. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    How do I parse a string eg. "01/21 - 02/20" which is represented as month/day to month/day. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I'm trying to convert a long timestamp that is UTC to Eastern Standard Time and am totally lost. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 7, 2022 in Education by JackTerrance
0 votes
    I'm trying to convert a long timestamp that is UTC to Eastern Standard Time and am totally lost. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    I have huge JSON files in a folder approx 200 each of 300 mbs approx. I need to write Spring ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    __________ stage of data science process helps in converting raw data into a machine-readable format....
asked Nov 16, 2022 in Education by JackTerrance
...