yavi icon indicating copy to clipboard operation
yavi copied to clipboard

Support Bean Validation Annotations via Annotation Processor to generate a Validator

Open making opened this issue 4 years ago • 5 comments

public class Message {
	@NotEmpty
	private String text;

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}
}

import am.ik.yavi.builder.ValidatorBuilder;
import am.ik.yavi.core.Validator;

public class Message_Validator {
	public static final Validator<Message> INSTANCE = ValidatorBuilder.<Message>of()
			.constraint(Message::getText, "text", c -> c.notEmpty())
			.build();
}

making avatar Jul 02 '21 04:07 making

I have written a few annotation processors and had something like this in mind. Is there a branch or separate repo where a prototype for this is located? Looking for help?

rbygrave avatar Jul 13 '21 23:07 rbygrave

@rbygrave https://github.com/making/yavi/tree/beanvalidation here it is. It’s a naive implementation. Nested constraints (@ Valid) are not supported yet

making avatar Jul 14 '21 01:07 making

Ah, it is in the same module - not a separate module. I was not expecting that. I guess I was also thinking about this as a potential drop in implementation for the standard BeanValidation Validator API which is perhaps a subtly different goal.

rbygrave avatar Jul 14 '21 03:07 rbygrave

It is now implemented as a Poc in the same repository. I think it will be another repository eventually.

making avatar Jul 14 '21 05:07 making

I guess I was also thinking about this as a potential drop in implementation for the standard BeanValidation

It would be great if the base part can be reusable :)

making avatar Jul 14 '21 05:07 making