// number of bytes to the stream
generator.close();
} catch (JsonMappingException e) {
throw new MongoJsonMappingException(e);
} catch (IOException e) {
throw new MongoException("Error writing object out", e);
}
return stream.getCount();
} else {
return defaultDBEncoder.writeObject(buf, object);
}