@Override
    protected String getKeyForPath(Path<?> expr, PathMetadata metadata) {
        AnnotatedElement annotations = expr.getAnnotatedElement();
        if (annotations.isAnnotationPresent(Id.class)) {
            Path<?> parent = expr.getMetadata().getParent();
            if (parent.getAnnotatedElement().isAnnotationPresent(Reference.class)) {
                return null; // go to parent
            } else {
                return "_id";
            }
        } else if (annotations.isAnnotationPresent(Property.class)) {
            Property property = annotations.getAnnotation(Property.class);
            if (!property.value().equals(Mapper.IGNORED_FIELDNAME)) {
                return property.value();
            }
        } else if (annotations.isAnnotationPresent(Reference.class)) {
            Reference reference = annotations.getAnnotation(Reference.class);
            if (!reference.value().equals(Mapper.IGNORED_FIELDNAME)) {
                return reference.value();
            }
        }
        return super.getKeyForPath(expr, metadata);
    }
{@code MorphiaSerializer} extends {@link MongodbSerializer} with Morphia specific annotation handling

@author tiwe
querydsl-mongodb/src/main/java/com/querydsl/mongodb/morphia/MorphiaSerializer.java