I have a field in a MongoDB document that stores an arbitrarily large number. When I retrieve it as a DBObject (Java driver for MongoDB), I sometimes throw a ClassCastException:
DBObject obj = collection.findOne();
long val = (Long)(o.get("numericVal"));
If the value stored in numericValis, say, 1234567890, casting to Long continues. If this is, say, 12345, DBObject.get () returns Double, and casting fails.
How can I ensure type safety when deserializing MongoDB DBObjects files?
source
share