@Override public void buildDbObject(DBObject dbObject, Object instance, Class<?> clazz, SessionImpl session) throws IllegalArgumentException, IllegalAccessException { for (Field eachField : session.getGraMongoSerializableFields(clazz)) { eachField.setAccessible(true); GraMongoSerializable<?> fieldValue = (GraMongoSerializable<?>) eachField.get(instance); if (fieldValue != null) { GraMongoBasicEntity basicEntity = fieldValue.serialize(); GraMongoSerializableConverter converter = new GraMongoSerializableConverter(basicEntity); dbObject.put(eachField.getName(), converter.convert()); } } }
@Override public void buildEntity(DBObject dbObject, Object instance, Class<?> clazz, SessionImpl session) throws IllegalArgumentException, IllegalAccessException { for (Field eachField : session.getGraMongoSerializableFields(clazz)) { DBObject fieldValue = (DBObject) dbObject.get(eachField.getName()); if (fieldValue != null) { @SuppressWarnings("unchecked") GraMongoBasicEntity graMongoBasicEntity = new GraMongoBasicEntity(fieldValue.toMap()); GraMongoSerializable<?> fieldInstance; try { fieldInstance = (GraMongoSerializable<?>) eachField.getType().newInstance(); eachField.set(instance, fieldInstance.deserialize(graMongoBasicEntity)); } catch (InstantiationException e) { new GraMongoException(e); } } } }