Skip to content

Commit

Permalink
HV-1420 Remove value handling section
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Aug 3, 2017
1 parent d317da1 commit a4362c5
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 277 deletions.
140 changes: 0 additions & 140 deletions documentation/src/main/asciidoc/ch12.asciidoc
Expand Up @@ -522,146 +522,6 @@ code at build time (via `DefaultParanamer`) and debug symbols (via `BytecodeRead
Alternatively you can specify a `Paranamer` implementation of your choice when creating a
`ParanamerParameterNameProvider` instance.

////
[[section-value-handling]]
=== Unwrapping values
Sometimes it is required to unwrap values prior to validating them. For example, in
<<example-using-unwrapvalidatedvalue>> a link:http://docs.oracle.com/javafx/[JavaFX] property type
is used to define an element of a domain model. The `@Size` constraint is meant to be applied to the
string value not the wrapping `Property` instance.
[[example-using-unwrapvalidatedvalue]]
.Applying a constraint to wrapped value of a JavaFX property
====
[source, JAVA, indent=0]
----
include::{sourcedir}/org/hibernate/validator/referenceguide/chapter12/valuehandling/Person.java[tags=javafxUnwrapValidatedValue]
----
====
[NOTE]
====
The concept of value unwrapping is considered experimental at this time and may evolve into more
general means of value handling in future releases. Please let us know about your use cases for such
functionality.
====
Bean properties in JavaFX are typically not of simple data types like `String` or `int`, but are
wrapped in `Property` types which allows to make them observable, use them for data binding etc. When
applying a constraint such as `@Size` to an element of type `Property<String>` without further
preparation, an exception would be raised, indicating that no suitable validator for that constraint
and data type can be found. Thus the validated value must be unwrapped from the containing property
object before looking up a validator and invoking it.
For unwrapping to occur a `ValidatedValueUnwrapper` needs to be registered for the type
requiring unwrapping. Example <<example-implementation-of-validatedvalueunwrapper>> shows how this
schematically looks for a JavaFX `PropertyValueUnwrapper`. You just need to extend the SPI class
`ValidatedValueUnwrapper` and implement its abstract methods.
[[example-implementation-of-validatedvalueunwrapper]]
.Implementing the ValidatedValueUnwrapper interface
====
[source, JAVA, indent=0]
----
include::{sourcedir}/org/hibernate/validator/referenceguide/chapter12/valuehandling/PropertyValueUnwrapper.java[tags=include]
----
====
The `ValidatedValueUnwrapper` needs also to be registered with the `ValidatorFactory`:
[[example-registering-validatedvalueunwrapper]]
.Registering a ValidatedValueUnwrapper
====
[source, JAVA, indent=0]
----
include::{sourcedir}/org/hibernate/validator/referenceguide/chapter12/valuehandling/UnwrapValidatedValueTest.java[tags=unwrapValidated]
----
====
Several unwrapper implementations can be registered. During constraint validator resolution
Hibernate Validator automatically checks whether a `ValidatedValueUnwrapper` exists for the validated
value. If so, unwrapping occurs automatically. In some cases, however, constraint validator instances
for a given constraint might exist for the wrapper as well as the wrapped value (`@NotNull` for example
applies to all objects). In this case Hibernate Validator needs to be explicitly told which value
to validate. This can be done via `@UnwrapValidatedValue(true)` respectively
`@UnwrapValidatedValue(false)`.
[NOTE]
====
Note that it is not specified which of the unwrapper implementations is
chosen when more than one implementation is suitable to unwrap a given element.
====
Instead of programmatically registering `ValidatedValueUnwrapper` types, the fully-qualified names
of one ore more unwrapper implementations can be specified
via the configuration property `hibernate.validator.validated_value_handlers` which can be useful when
configuring the default validator factory using the descriptor _META-INF/validation.xml_ (see
<<chapter-xml-configuration>>).
[[section-optional-unwrapper]]
==== Optional unwrapper
Hibernate Validator provides built-in unwrapping for `Optional` introduced in Java 8.
The unwrapper is registered automatically in Java 8 environments, and no further configuration is
required. An example of unwrapping an `Optional` instance is shown in
<<example-using-unwrapvalidatedvalue-and-optional>>.
[[example-using-unwrapvalidatedvalue-and-optional]]
.Unwrapping `Optional` instances
====
[source, JAVA, indent=0]
----
include::{sourcedir}/org/hibernate/validator/referenceguide/chapter12/valuehandling/Person.java[tags=optional]
----
====
[NOTE]
====
`Optional.empty()` is treated as `null` during validation. This means that for constraints where
`null` is considered valid, `Optional.empty()` is similarly valid.
====
[[section-javafx-unwrapper]]
==== JavaFX unwrapper
Hibernate Validator also provides built-in unwrapping for JavaFX property values. The unwrapper is
registered automatically for environments where JavaFX is present, and no further configuration is
required. `ObservableValue` and its sub-types are supported.
An example of some of the different ways in which `JavaFX` property values can be unwrapped is
shown in <<example-using-unwrapvalidatedvalue-and-javafx>>.
[[example-using-unwrapvalidatedvalue-and-javafx]]
.Unwrapping `JavaFX` properties
====
[source, JAVA, indent=0]
----
include::{sourcedir}/org/hibernate/validator/referenceguide/chapter12/valuehandling/Person.java[tags=javafx]
----
====
==== Unwrapping object graphs
Unwrapping can also be used with object graphs (cascaded validation) as shown in
<<example-using-unwrapvalidatedvalue-and-optional-with-valid>>.
When validating the object holding the `Optional<Person>`, a cascaded validation of the `Person`
object would be performed.
[[example-using-unwrapvalidatedvalue-and-optional-with-valid]]
.Unwrapping `Optional` prior to cascaded validation via `@Valid`
====
[source, JAVA, indent=0]
----
include::{sourcedir}/org/hibernate/validator/referenceguide/chapter12/valuehandling/graph/Container.java[tags=include]
----
[source, JAVA, indent=0]
----
include::{sourcedir}/org/hibernate/validator/referenceguide/chapter12/valuehandling/graph/Person.java[tags=include]
----
====
////

[[section-constraint-definition-contribution]]
=== Providing constraint definitions

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit a4362c5

Please sign in to comment.