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,821
  • 6
  • 77
  • 100
Yogesh Prajapati
  • 4,770
  • 2
  • 36
  • 77

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
  • 64,778
  • 30
  • 169
  • 213