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?

1
  • Try to convert string with gson after that use jodatime to be able to convert Java util Date format. Commented Jan 5, 2015 at 19:12

1 Answer 1

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

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.