Hi everybody,
I'm trying to fo
llow the MongoJack tutorial but I'm failing the first task: Inserting an object into the database.
This is what I have:
DB db = new MongoClient().getDB("mydb");
JacksonDBCollection<MyDomainObject, String> coll =
JacksonDBCollection.wrap(db.getCollection("coll"),
MyDomainObject.class,
String.class);
MyDomainObject obj = new MyDomainObject(ObjectId.get().toString(), 123456789L);
WriteResult<MyDomainObject, String> result = coll.insert(obj);
System.out.println(result.getSavedId()); // Throws java.lang.ClassCastException: org.bson.types.ObjectId cannot be cast to java.lang.String
Where MyDomainObject
class looks as follows:
class MyDomainObject {
// @org.mongojack.ObjectId doesn't work
public String id;
public long someValue;
public MyDomainObject(String id, long someValue) {
this.id = id;
this.someValue = someValue;
}
}
I can't for my life figure out why. Any help appreciated.
best regards,
Andreas