Reputation: 4870
I am getting this JSON from mongoDB
{
"_id" : ObjectId("4f95bbe3742b1eaa929b81ef"),
"empNo" : NumberLong(10),
"empName" : "abc",
"joinDate" : ISODate("2012-04-23T20:30:27.421Z"),
"address" : {
"addNo" : NumberLong(1),
"addLocation" : "add0",
"street" : {
"sNo" : NumberLong(10),
"sName" : "Street 1"
}
}
}
I want to convert ISODate("2012-04-23T20:30:27.421Z")
to Java Date.
I am getting an error while converting the JSON to Object using Google's Gson Library when Date Atribute is there.
What is the correct way to do this?
Upvotes: 2
Views: 6409
Reputation: 65877
Mongo date is a ISO formatted. You can use ISODateTimeFormat
of Joda-time library to convert ISO date string to java data object.
Check out converting-iso8601-compliant-string-to-java-util-date for more info
Upvotes: 3