0

I am using JDBC Template to get the values from the DB ,and storing the result in List> as the number of columns returned by my Template is not fixed.

So if there is any date field coming in the output , while setting it into the json variable of List> am getting the date printed as Timestamp in the output , but I need the date to get printed .

Tried using Object mapper and setting the date format using simple date formatter , but while setting into JSON it is again taking as a timestamp.

Since this is an Object that too we 'll begetting it dynamically , so I cant judge when there'll be date coming in my output.

3
  • 3
    Please show to code you are talking about Commented Feb 10, 2017 at 6:14
  • In JSON you'll have to serialize your date to some other format, which is usually either a string (ISO 8601) or a number (UNIX timestamp). To parse it to Dates in JavaScript, I usually write a function that recurses through the entire object, looks if the given string is an ISO 8601 timestamp (by using a regular expression) and then I automatically convert all those string to Dates. Commented Feb 10, 2017 at 7:13
  • Tips: java.time & ISO 8601. Commented Feb 11, 2017 at 2:29

1 Answer 1

2

JSON doesn't support Date objects it only supports Number, String, Boolean, and Array of those items.

So you will have to either do it as a formatted String already in the format you require or do it as a timestamp Number and then format through some type of library.

For JavaScript I use moment.js and for C# and Java I use the standard date and calendar objects available for those languages.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.