I am using Mongo DB and on saveData method I'm trying to save the data object on Mongo DB. First I am converting the data object in JSON format and after I save the object on Mongo DB. But there's a problem. My Class Object has a atribute initialDate with Date Type, but when this code saves the object on Mongo the initialDate atribute is saved as a string, but I need that it be saved in date format. Someone can help me?
public void saveData(ClassObject data) {
JSONObject jsonObject = new JSONObject(data);
String dataJson = jsonObject.toString();
DBObject dbObject = (DBObject) JSON.parse(dataJson);
DBCollection table = mongoDB.getCollection(data
.getModel().getProjectName());
table.insert(dbObject);
}
Here the ClassObject
Class ClassObject {
private int value;
private ParentModel model;
private Date initialDate;
...
//here get and setters
}