0

I am using NosqlUnit, Fongo, Spring-Data-MongoDB

my dataset format like below.

{
    "people" : {
        "data" : [
            {
                "key" : "12345",
                "phone" : "33333",
                "register" : "2011-01-05T10:09:15.210Z", //It is ISODate, How can I convert Joda DateTime?
                "index" : 1
            }
        ]
    }
}

my domain object like this,

  @Id
  private ObjectId id;

  @Field("key")
  private String key;

  @Field("phone")
  private String phone;

  @Indexed(unique=true, direction=IndexDirection.DESCENDING)
  @Field("index")
  private long index;

  @Field("register")
  private DateTime register;

But register always null

Thanks for your help

moon
  • 165
  • 1
  • 3
  • 6
  • it's perhaps a bug in fongo. Can you report an issue https://github.com/fakemongo/fongo/issues ? – twillouer Dec 19 '15 at 07:41
  • @twillouer Thanks. I will report this issue – moon Dec 21 '15 at 00:55
  • Are you trying to convert the register key output (format is ISODate) to Joda DateTime? Or are you trying to convert Joda DateTime to ISODate – Daniel Jul 18 '16 at 15:58

1 Answers1

0

Since you didn't bother to forward the answer that was given to you on the fongo repository issue section...

Use the MongoDB extended JSON strict mode notation for dates, using the ISO 8601 UTC notation (not the one with localtime and timeoffset that is parsed incorrectly), as explained here and here:

{
    "people" : {
        "data" : [
            {
                "key" : "12345",
                "phone" : "33333",
                "register" : { "$date" : "2011-01-05T10:09:15.210Z" }, 
                "index" : 1
            }
        ]
    }
}
Marc Tarin
  • 3,109
  • 17
  • 49