Reputation: 1715
Lets say I've an one-column-table like this:
CREATE TABLE test (
id int,
time timestamp,
PRIMARY KEY(id)
);
Now I insert data per Json:
INSERT INTO test JSON '{"id":1,"time":"2018-01-12T15:06:02.753Z"}'
The result would look like this:
id time
1 2018-01-12 15:06:02.753+0000
Now I select the entry again as Json:
SELECT JSON * from test where id=1;
The resulting Json would look like this:
{
"id":1,
"time":"2018-01-12 15:06:02.753+0000"
}
If I now want to parse the field "time" in the json above to an Instant, it fails because of a whitespace:
Exception in thread "main" java.time.format.DateTimeParseException: Text '2018-01-12 10:23:00.461Z' could not be parsed at index 10
I could replace the whitespace-Charakter with a 'T'-Delimiter, but is there an better way to parse an Instant?
Upvotes: 1
Views: 636
Reputation: 2430
Datastax Java driver supports table to object mapping out-of-the box. You don't have to write the code by yourself.
Timestamps are automatically mapped to java.util.Date
objects by Java driver. See some related documentation below:
Upvotes: 1