mardi 3 mars 2015

JsonMappingException while deserializing Object from mongodb by jackson lib

I have documents saved in mongodb and Im fetching data as I show below. I am deserializing DBObject(json string) to object by jackson. However Im getting this exception org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.Date out of START_OBJECT token. The date field is like that in the json string. Any help would be appreciated.



"eventStartDate" : { "$date" : "2015-02-27T21:48:04.452Z"}

BasicDBObject bdo = new BasicDBObject("$near", location);
bdo.put("$maxDistance", 100);
bdo.put("$minDistance", 1);

final BasicDBObject query = new BasicDBObject("event.address.location", bdo);

List<Events> ads = mo.execute("evt", new CollectionCallback<List<Events>>() {
@Override
public List<Events> doInCollection(DBCollection collection) throws MongoException, DataAccessException {
DBCursor c = collection.find(query);
ObjectMapper oom = new ObjectMapper();
List<Events> ads = new ArrayList<Events>();
for(DBObject dos : c){
Events a = null;
try {
a = oom.readValue(dos.toString(), Events.class);
ads.add(a);
} catch (Exception e) {
logger.error(e);
}
}
return ads;
}
});

Aucun commentaire:

Enregistrer un commentaire