### Question:
UtilMongoDB { public static <T> T getObjectFromBson(Class<T> classEntity, BSONObject bsonObject) throws IllegalAccessException, InstantiationException, InvocationTargetException { T t = classEntity.newInstance(); Field[] fields = AnnotationUtils.filterDeepFields(classEntity); Object insert = null; for (Field field : fields) { Object currentBson = null; Method method = null; try { method = Utils.findSetter(field.getName(), classEntity, field.getType()); Class<?> classField = field.getType(); currentBson = bsonObject.get(AnnotationUtils.deepFieldName(field)); if (currentBson != null) { if (Iterable.class.isAssignableFrom(classField)) { Type type = field.getGenericType(); insert = subDocumentListCase(type, (List) bsonObject.get(AnnotationUtils.deepFieldName(field))); } else if (IDeepType.class.isAssignableFrom(classField)) { insert = getObjectFromBson(classField, (BSONObject) bsonObject.get(AnnotationUtils.deepFieldName (field))); } else { insert = currentBson; } method.invoke(t, insert); } } catch (IllegalAccessException | InstantiationException | InvocationTargetException | IllegalArgumentException e) { LOG.error("impossible to create a java object from Bson field:" + field.getName() + " and type:" + field .getType() + " and value:" + t + "; bsonReceived:" + currentBson + ", bsonClassReceived:" + currentBson.getClass()); method.invoke(t, Utils.castNumberType(insert, t.getClass())); } } return t; } private  UtilMongoDB(); static T getObjectFromBson(Class<T> classEntity, BSONObject bsonObject); static DBObject getBsonFromObject(T t); static Object getId(T t); static Cells getCellFromBson(BSONObject bsonObject, String tableName); static DBObject getDBObjectFromCell(Cells cells); static final String MONGO_DEFAULT_ID; }### Answer:
@Test public void testGetObjectFromBson() throws UnknownHostException, NoSuchFieldException, IllegalAccessException, InvocationTargetException, InstantiationException { BSONObject bson = createBsonTest(); BookEntity bookEntity = UtilMongoDB.getObjectFromBson(BookEntity.class, bson); MetadataEntity metadata = bookEntity.getMetadataEntity(); assertEquals(metadata.getAuthor(), AUTHOR); assertEquals(metadata.getTitle(), TITLE); assertEquals(metadata.getSource(), SOURCE); List<CantoEntity> cantoEntityList = bookEntity.getCantoEntities(); assertEquals(cantoEntityList.get(0).getNumber(), CANTO_I); assertEquals(cantoEntityList.get(0).getText(), TEXT_I); assertEquals(cantoEntityList.get(1).getNumber(), CANTO_II); assertEquals(cantoEntityList.get(1).getText(), TEXT_II); }