- All Known Subinterfaces:
Body,Formdata,QueryString,ValueNode,WebSocketMessage
- All Known Implementing Classes:
ForwardingContext.ForwardingBody,ForwardingContext.ForwardingFormdata,ForwardingContext.ForwardingQueryString,ForwardingContext.ForwardingValueNode,ValidationContext.ValidatedBody,ValidationContext.ValidatedFormdata,ValidationContext.ValidatedQueryString,ValidationContext.ValidatedValue
- unify access to HTTP values, like query, path, form and header parameter - works as validation API, because it is able to check for required and type-safe values
The value API is composed by three types:
- Single value - Object value - Sequence of values (array)
Single value are can be converted to string, int, boolean, enum like values. Object value is a key:value structure (like a hash). Sequence of values are index based structure.
All these 3 types are modeled into a single Value class. At any time you can treat a value as 1) single, 2) hash or 3) array of them.
- Since:
- 2.0.0
- Author:
- edgar
-
Method Summary
Modifier and TypeMethodDescriptionstatic ValueNodeCreates a sequence/array of values.default booleanConvert this value to boolean (if possible).default booleanbooleanValue(boolean defaultValue) Convert this value to boolean (if possible) or fallback to given value when missing.default byteConvert this value to byte (if possible).default bytebyteValue(byte defaultValue) Convert this value to byte (if possible) or fallback to given value when missing.static ValueNodeCreates a value that fits better with the given values.static ValueNodeCreates a value that fits better with the given values.default doubleConvert this value to double (if possible).default doubledoubleValue(double defaultValue) Convert this value to double (if possible) or fallback to given value when missing.default floatConvert this value to float (if possible).default floatfloatValue(float defaultValue) Convert this value to float (if possible) or fallback to given value when missing.static FormdataCreates a formdata.static ValueNodeCreate a hash/object value using the map values.static ValueNodeCreate a hash/object value using the map values.default intintValue()Convert this value to int (if possible).default intintValue(int defaultValue) Convert this value to int (if possible) or fallback to given value when missing.default booleanisArray()True if this value is an array/sequence (not single or hash).default booleanTrue for missing values.default booleanisObject()True if this is a hash/object value (not single or array).default booleanTrue for present values.default booleanisSingle()True if this is a single value (not a hash or array).default longConvert this value to long (if possible).default longlongValue(long defaultValue) Convert this value to long (if possible) or fallback to given value when missing.static ValueNodeCreates a missing value.name()Name of this value ornull.<T> TConvert this value to the given type.default <T extends Enum<T>>
TtoEnum(SneakyThrows.Function<String, T> fn) Convert this value to an Enum.default <T extends Enum<T>>
TConvert this value to an Enum.toList()Get list of values.default <T> List<T>Get list of the given type.toMap()Value as single-value map.Value as multi-value map.<T> TtoNullable(Class<T> type) Convert this value to the given type.Get a value or empty optional.default <T> Optional<T>toOptional(Class<T> type) Get a value or empty optional.toSet()Get set of values.default <T> Set<T>Get set of the given type.value()Get string value.static ValueNodeCreates a single value.default <T> Tvalue(SneakyThrows.Function<String, T> fn) Convert value using the given function.default StringConvert this value to String (if possible) or fallback to given value when missing.default StringConvert this value to String (if possible) ornullwhen missing.
-
Method Details
-
longValue
default long longValue()Convert this value to long (if possible).- Returns:
- Long value.
-
longValue
default long longValue(long defaultValue) Convert this value to long (if possible) or fallback to given value when missing.- Parameters:
defaultValue- Default value.- Returns:
- Convert this value to long (if possible) or fallback to given value when missing.
-
intValue
default int intValue()Convert this value to int (if possible).- Returns:
- Int value.
-
intValue
default int intValue(int defaultValue) Convert this value to int (if possible) or fallback to given value when missing.- Parameters:
defaultValue- Default value.- Returns:
- Convert this value to int (if possible) or fallback to given value when missing.
-
byteValue
default byte byteValue()Convert this value to byte (if possible).- Returns:
- Convert this value to byte (if possible).
-
byteValue
default byte byteValue(byte defaultValue) Convert this value to byte (if possible) or fallback to given value when missing.- Parameters:
defaultValue- Default value.- Returns:
- Convert this value to byte (if possible) or fallback to given value when missing.
-
floatValue
default float floatValue()Convert this value to float (if possible).- Returns:
- Convert this value to float (if possible).
-
floatValue
default float floatValue(float defaultValue) Convert this value to float (if possible) or fallback to given value when missing.- Parameters:
defaultValue- Default value.- Returns:
- Convert this value to float (if possible) or fallback to given value when missing.
-
doubleValue
default double doubleValue()Convert this value to double (if possible).- Returns:
- Convert this value to double (if possible).
-
doubleValue
default double doubleValue(double defaultValue) Convert this value to double (if possible) or fallback to given value when missing.- Parameters:
defaultValue- Default value.- Returns:
- Convert this value to double (if possible) or fallback to given value when missing.
-
booleanValue
default boolean booleanValue()Convert this value to boolean (if possible).- Returns:
- Convert this value to boolean (if possible).
-
booleanValue
default boolean booleanValue(boolean defaultValue) Convert this value to boolean (if possible) or fallback to given value when missing.- Parameters:
defaultValue- Default value.- Returns:
- Convert this value to boolean (if possible) or fallback to given value when missing.
-
value
Convert this value to String (if possible) or fallback to given value when missing.- Parameters:
defaultValue- Default value.- Returns:
- Convert this value to String (if possible) or fallback to given value when missing.
-
valueOrNull
Convert this value to String (if possible) ornullwhen missing.- Returns:
- Convert this value to String (if possible) or
nullwhen missing.
-
value
Convert value using the given function.- Type Parameters:
T- Target type.- Parameters:
fn- Function.- Returns:
- Converted value.
-
value
Get string value.- Returns:
- String value.
-
toList
Get list of values.- Returns:
- List of values.
-
toSet
Get set of values.- Returns:
- set of values.
-
toEnum
Convert this value to an Enum.- Type Parameters:
T- Enum type.- Parameters:
fn- Mapping function.- Returns:
- Enum.
-
toEnum
@NonNull default <T extends Enum<T>> T toEnum(@NonNull SneakyThrows.Function<String, T> fn, @NonNull Function<String, String> nameProvider) Convert this value to an Enum.- Type Parameters:
T- Enum type.- Parameters:
fn- Mapping function.nameProvider- Enum name provider.- Returns:
- Enum.
-
toOptional
Get a value or empty optional.- Returns:
- Value or empty optional.
-
isSingle
default boolean isSingle()True if this is a single value (not a hash or array).- Returns:
- True if this is a single value (not a hash or array).
-
isMissing
default boolean isMissing()True for missing values.- Returns:
- True for missing values.
-
isPresent
default boolean isPresent()True for present values.- Returns:
- True for present values.
-
isArray
default boolean isArray()True if this value is an array/sequence (not single or hash).- Returns:
- True if this value is an array/sequence.
-
isObject
default boolean isObject()True if this is a hash/object value (not single or array).- Returns:
- True if this is a hash/object value (not single or array).
-
name
Name of this value ornull.- Returns:
- Name of this value or
null.
-
toOptional
Get a value or empty optional.- Type Parameters:
T- Item type.- Parameters:
type- Item type.- Returns:
- Value or empty optional.
-
toList
Get list of the given type.- Type Parameters:
T- Item type.- Parameters:
type- Type to convert.- Returns:
- List of items.
-
toSet
Get set of the given type.- Type Parameters:
T- Item type.- Parameters:
type- Type to convert.- Returns:
- Set of items.
-
to
Convert this value to the given type. Support values are single-value, array-value and object-value. Object-value can be converted to a JavaBean type.- Type Parameters:
T- Element type.- Parameters:
type- Type to convert.- Returns:
- Instance of the type.
-
toNullable
Convert this value to the given type. Support values are single-value, array-value and object-value. Object-value can be converted to a JavaBean type.- Type Parameters:
T- Element type.- Parameters:
type- Type to convert.- Returns:
- Instance of the type or
null.
-
toMultimap
Value as multi-value map.- Returns:
- Value as multi-value map.
-
toMap
Value as single-value map.- Returns:
- Value as single-value map.
-
missing
Creates a missing value.- Parameters:
name- Name of missing value.- Returns:
- Missing value.
-
value
Creates a single value.- Parameters:
ctx- Current context.name- Name of value.value- Value.- Returns:
- Single value.
-
array
@NonNull static ValueNode array(@NonNull Context ctx, @NonNull String name, @NonNull List<String> values) Creates a sequence/array of values.- Parameters:
ctx- Current context.name- Name of array.values- Field values.- Returns:
- Array value.
-
create
Creates a value that fits better with the given values.- For null/empty values. It produces a missing value. - For single element (size==1). It produces a single value - For multi-value elements (size>1). It produces an array value.
- Parameters:
ctx- Current context.name- Field name.values- Field values.- Returns:
- A value.
-
create
Creates a value that fits better with the given values.- For null/empty values. It produces a missing value. - For single element (size==1). It produces a single value
- Parameters:
ctx- Current context.name- Field name.value- Field values.- Returns:
- A value.
-
hash
Create a hash/object value using the map values.- Parameters:
ctx- Current context.values- Map values.- Returns:
- A hash/object value.
-
formdata
Creates a formdata.- Parameters:
ctx- Current context.- Returns:
- A hash/object value.
-
headers
Create a hash/object value using the map values.- Parameters:
ctx- Current context.values- Map values.- Returns:
- A hash/object value.
-