} else if (value instanceof String) {
return new ObjectId((String) value);
} else if (value instanceof byte[]) {
return new ObjectId((byte[]) value);
} else if (value instanceof DBRef) {
DBRef dbRef = (DBRef) value;
Object id = serialiseObject(dbRef.getId());
if (id == null) {
return null;
}
return new com.mongodb.DBRef(null, dbRef.getCollectionName(), id);
} else if (value instanceof ObjectId) {
return value;
} else {
throw new JsonMappingException("Cannot deserialise object of type " + value.getClass() + " to ObjectId");
}