Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for inheritance hierarchies validation #278

Open
alexshavlovsky opened this issue Sep 5, 2022 · 1 comment
Open

Add support for inheritance hierarchies validation #278

alexshavlovsky opened this issue Sep 5, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@alexshavlovsky
Copy link

Now I treat inheritance as follows:

    ValidatorBuilder.<Parent>of()
                // constraints for parent
                .constraint(...)
                .constraint(...)
                .constraintOnCondition(
                        isInstanceOf(Child.class), b -> b
                                .nest(Child.class::cast, "(CHILD)", b2 -> b2
                                        // constraints for child
                                        .constraint(...)
                                        .constraint(...)
                                        .constraint(...)
                                )
                )

    public static <T, A extends T> ConstraintCondition<T> isInstanceOf(Class<A> aClass) {
        return (target, ctx) -> target.getClass() == aClass;
    }

It would be good to have something like:

    ValidatorBuilder.<Parent>of()
                // constraints for parent
                .constraint(...)
                .constraint(...)
                .constraintOnClass(Child.class), b -> b
                            // constraints for child
                            .constraint(...)
                            .constraint(...)
                            .constraint(...)
                    )
                )

Best Regards!!!!

@making
Copy link
Owner

making commented Nov 17, 2022

Having such a shortcut method looks good
PR is welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants