2

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?

Eliran Malka
  • 15,305
  • 5
  • 75
  • 98
Yogesh Prajapati
  • 4,608
  • 2
  • 31
  • 72

1 Answers1

3

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

Community
  • 1
  • 1
RameshVel
  • 62,788
  • 28
  • 167
  • 209