Hi guys!
I didn't find any topic on this new feature (@UnwrapValidatedValue), so here's one now. :)
I'll start with a bit special situation with which I'm having difficulties implementing:
I want to make null wrappers valid, but not null-valued wrappers. What?! Here's an example:
Code:
@NotNull
@UnwrapValidatedValue
private Wrapper<String> field;
Now, assume Wrapper<T> has a member "value" of type T and that there's an appropriate ValidatedValueUnwrapper. What this means, is that field.value should not be null. Implicitly it also means that field should not be null, but I do not want that. Of course I can unwrap nulls in handleValidatedValue to some String, but it's not a general solution as other constraints (like Size) may be defined, also there could be other types wrapped in Wrapper. So unless there's an "always valid object" for all constraints and types, this is not going to work. :)
The issue is many-fold, but generally speaking the main problem - I believe - is that I'm trying to validate both the wrapper and the wrapped value. So maybe I'm expecting too much, but I think in practice this issue only arises for the NotNull constraint.
Here's my exact use-case, if you're interested:
I'm developing a REST-like API, where to support the differentiation between not-defined fields and fields explicitly set to null in the POST-ed JSON objects, I introduced a wrapping: If the wrapper itself is null than the field was not set (undefined), if the field was set to null than the wrapper's "value" member is set to null. To understand why does it matter, consider a (partial) update: undefined fields should not be changed, while null-valued fields should be set to null. Now if a field has a NotNull constraint, it beeing undefined is still valid (
in case of an update).