Skip to content

Question: Working with Protobuf types #83

Open
@viniciusccarvalho

Description

@viniciusccarvalho

First, this is a pretty cool library, I'm glad I found it, and hoping to make it standard on my projects.

I did bump into a small issue, working with protobuf types.

Let's say I have a protobuf that looks like this:

message User {

Address address = 1;
Vehicle vehicle = 2;

}

And if I write:

 ruleFor(User::getAddress)
                .must(not(nullValue()))

That would never match, because the proto java class will generate a default Address object even if the caller has not passed one.

I attempted to use

ruleFor(user -> user)
.must(isTrue(user.hasAddress())
.withMessage(...)
.whenever(isTrue(user.hasAddress())
.withValidator(new AddressValidator())

But the problem is that down the chain if I want to use whenever, its expecting a Boolean from the first must predicate I guess.

Is there a way around this? I ended up using critical at a validation and the next one I'd do the custom validator, but bumped into another problem, now, if address is empty/null Vehicle never gets a chance to be checked.

Any suggestions?

Once again, awesome library dude!

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions