I use org.springframework.data.mongodb.core.MongoTemplate to save data to MongoDB. My sample data is following bean:
public class SampleBean{
private Date date;
private List<Date> datesList;
private TreeMap<Date, Integer> datesMap;
// setters and getters
}
I am calling following instructions.
SampleBean bean = new SampleBean();
MongoTemplate mongo = new MongoTemplate();
List<Date> dateList = new ArrayList<Date>();
dateList.add(new Date());
TreeMap<Date,Integer> dateMap = new TreeMap<Date, Integer>();
dateMap.put(new Date(), new Integer(1));
bean.setDate(new Date());
bean.setDateList(dateList);
bean.setDateMap(dateMap);
mongo.save(bean, "SampleBean");
And this is what i get in mongo:
{
"_id" : ObjectId("53d028eeb71a1523582b1b1c"),
"_class" : "example.SampleBean",
"date" : ISODate("2014-07-23T21:28:14.869Z"),
"datesList" : [
ISODate("2014-07-23T21:28:14.876Z")
],
"datesMap" : {
"Wed Jul 23 23:28:14 CEST 2014" : 1
}
}
Because of way it's stored I am not able to load bean from MongoDB
I get
Handler execution resulted in exception - forwarding to resolved error view
org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type java.util.Date for value 'Wed Jul 23 23:28:14 CEST 2014'; nested exception is java.lang.IllegalArgumentException
Why Date from TreeMap is not stored as ISODate?
Am I doing anything wrong?