Top Description Inners Methods
jakarta.validation.valueextraction

public Interface ValueExtractor<T>

Type Parameters
<T>
the container type handled by a specific implementation
Imports
java.util.List, .Map, .Optional, .OptionalInt, .Set, jakarta.validation.Path

Defines the logic used to extract the values from a container object of type T.

A value extractor for a generic type such as Optional, List or Map is tied to one specific type parameter of T. The ExtractedValue annotation is used to mark that type parameter. A value extractor for a non-generic type such as OptionalInt needs to declare the type of the wrapped element(s) using ExtractedValue#type().

The extracted values are passed to the corresponding method of the ValueReceiver.

A typical value extractor implementation for List may look like this:

public class ListValueExtractor implements
        ValueExtractor<List<@ExtractedValue ?>> {

    @Override
    public void extractValues(List<?> originalValue, ValueReceiver receiver) {
        for ( int i = 0; i < originalValue.size(); i++ ) {
            receiver.indexedValue( "<list element>", i, originalValue.get( i ) );
        }
    }
}
Authors
Gunnar Morling, Guillaume Smet
Since
2.0
See Also
ExtractedValue, UnwrapByDefault

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ValueExtractor.ValueReceiver

Provides a set of methods receiving value extracted by the ValueExtractor.

Method Summary

Modifier and TypeMethod and Description
public void
extractValues(T
the original value from which to extract the values, never null
originalValue
,
ValueExtractor.ValueReceiver
the corresponding ValueReceiver
receiver
)

Extracts the values to validate from the original object.

Method Detail

extractValuesback to summary
public void extractValues(T originalValue, ValueExtractor.ValueReceiver receiver)

Extracts the values to validate from the original object.

Parameters
originalValue:T

the original value from which to extract the values, never null

receiver:ValueExtractor.ValueReceiver

the corresponding ValueReceiver

jakarta.validation.valueextraction back to summary

public Interface ValueExtractor.ValueReceiver


Provides a set of methods receiving value extracted by the ValueExtractor.

The value has to be passed to the method corresponding best to the type of the original value.

Since
2.0

Method Summary

Modifier and TypeMethod and Description
public void
indexedValue(String
the name of the node representing the container element. If not null, the name will be used when adding a container element node to the Path
nodeName
,
int
the index of the value in the original object
i
,
Object
the value to validate
object
)

Receives the value extracted from an indexed object (e.g. a List).

public void
iterableValue(String
the name of the node representing the container element. If not null, the name will be used when adding a container element node to the Path
nodeName
,
Object
the value to validate
object
)

Receives the value extracted from an iterable object that is not indexed (e.g. a Iterable, Set or a Map).

public void
keyedValue(String
the name of the node representing the container element. If not null, the name will be used when adding a container element node to the Path
nodeName
,
Object
the key of the value in the original object
key
,
Object
the value to validate
object
)

Receives the value extracted from a keyed object (e.g. a Map).

public void
value(String
the name of the node representing the container element. If not null, the name will be used when adding a container element node to the Path
nodeName
,
Object
the value to validate
object
)

Receives the value extracted from an object.

Method Detail

indexedValueback to summary
public void indexedValue(String nodeName, int i, Object object)

Receives the value extracted from an indexed object (e.g. a List).

Parameters
nodeName:String

the name of the node representing the container element. If not null, the name will be used when adding a container element node to the Path

i:int

the index of the value in the original object

object:Object

the value to validate

iterableValueback to summary
public void iterableValue(String nodeName, Object object)

Receives the value extracted from an iterable object that is not indexed (e.g. a Iterable, Set or a Map).

Parameters
nodeName:String

the name of the node representing the container element. If not null, the name will be used when adding a container element node to the Path

object:Object

the value to validate

keyedValueback to summary
public void keyedValue(String nodeName, Object key, Object object)

Receives the value extracted from a keyed object (e.g. a Map).

Parameters
nodeName:String

the name of the node representing the container element. If not null, the name will be used when adding a container element node to the Path

key:Object

the key of the value in the original object

object:Object

the value to validate

valueback to summary
public void value(String nodeName, Object object)

Receives the value extracted from an object.

Parameters
nodeName:String

the name of the node representing the container element. If not null, the name will be used when adding a container element node to the Path

object:Object

the value to validate