I'd like to create an annotation
which effectively acts exactly as javax.annotation.Nullable
. The reason I need this is that I just need a different name for it in my context.
The problem is that I have a field that has to acts as Nullable
for the AutoValue
so that it doesn't autogenerate the code for throwing exception if the value is null
. And at the same time, I need the value to be NotNull
for the JSR-303 validation.
In simple terms, I want to be able to build my object to invalid state, and then pass it to the validator that will do something about it. I want to have all validation handled by Hibernate Validator API
that will generate violation constraints without crashing my program with the exception.
So I found out that the following will do what I want.
public abstract @Nullable @NotNull @Size(min = 3, max = 20) String getBane();
This will cause AutoValue
to not throw exception if the value is not there, but Hibernate Validator will still validate that it should not be null. The only problem here is the word "Nullable", I'd like to call it "AutoValueNullable".
How would I "reinvent" the Nullable, or is there an open source code of it?