Top Description Inners Fields Constructors Methods
org.springframework.web.bind.support

public Class WebExchangeDataBinder

extends WebDataBinder
Class Inheritance
Imports
java.util.List, .Map, .Set, .TreeMap, reactor.core.publisher.Mono, org.springframework.beans.MutablePropertyValues, org.springframework.core.MethodParameter, org.springframework.http.codec.multipart.FormFieldPart, .Part, org.springframework.lang.Nullable, org.springframework.util.CollectionUtils, .MultiValueMap, org.springframework.web.bind.WebDataBinder, org.springframework.web.server.ServerWebExchange

Specialized org.springframework.validation.DataBinder to perform data binding from URL query parameters or form data in the request data to Java objects.

Warning

Data binding can lead to security issues by exposing parts of the object graph that are not meant to be accessed or modified by external clients. Therefore the design and use of data binding should be considered carefully with regard to security. For more details, please refer to the dedicated sections on data binding for Spring Web MVC and Spring WebFlux in the reference manual.

Authors
Rossen Stoyanchev, Juergen Hoeller
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
WebExchangeDataBinder.MapValueResolver

Resolve values from a map.

Field Summary

Inherited from org.springframework.web.bind.WebDataBinder:
DEFAULT_FIELD_DEFAULT_PREFIXDEFAULT_FIELD_MARKER_PREFIX

Constructor Summary

AccessConstructor and Description
public
WebExchangeDataBinder(Object
the target object to bind onto (or null if the binder is just used to convert a plain parameter value)
target
)

Create a new instance, with default object name.

public
WebExchangeDataBinder(Object
the target object to bind onto (or null if the binder is just used to convert a plain parameter value)
target
,
String
the name of the target object
objectName
)

Create a new instance.

Method Summary

Modifier and TypeMethod and Description
protected static void
addBindValue(Map<String, Object> params, String key, List<?> values)

public Mono<Void>

Returns:

a Mono<Void> that completes when binding is complete
bind
(ServerWebExchange
the current exchange
exchange
)

Bind query parameters, form data, or multipart form data to the binder target.

public Mono<Void>

Returns:

a Mono<Void> that completes when the target is created
construct
(ServerWebExchange
the request to bind
exchange
)

Use a default or single data constructor to create the target by binding request parameters, multipart files, or parts to constructor args.

public static Mono<Map<String, Object>>

Returns:

a Mono with the values to bind
extractValuesToBind
(ServerWebExchange
the current exchange
exchange
)

Combine query params and form data for multipart form data from the body of the request into a Map<String, Object> of values to use for data binding purposes.

public Mono<Map<String, Object>>

Returns:

a map of bind values
getValuesToBind
(ServerWebExchange
the current exchange
exchange
)

Obtain the values for data binding.

protected boolean
shouldConstructArgument(MethodParameter param)

Overrides org.springframework.validation.DataBinder.shouldConstructArgument.

Whether to instantiate the constructor argument of the given type, matching its own constructor arguments to bind values.
Inherited from org.springframework.web.bind.WebDataBinder:
adaptEmptyArrayIndicesbindMultipartcheckFieldDefaultscheckFieldMarkersdoBindgetEmptyValuegetEmptyValuegetFieldDefaultPrefixgetFieldMarkerPrefixisBindEmptyMultipartFilesresolvePrefixValuesetBindEmptyMultipartFilessetFieldDefaultPrefixsetFieldMarkerPrefix

Constructor Detail

WebExchangeDataBinderback to summary
public WebExchangeDataBinder(Object target)

Create a new instance, with default object name.

Parameters
target:Object

the target object to bind onto (or null if the binder is just used to convert a plain parameter value)

See Also
DEFAULT_OBJECT_NAME
WebExchangeDataBinderback to summary
public WebExchangeDataBinder(Object target, String objectName)

Create a new instance.

Parameters
target:Object

the target object to bind onto (or null if the binder is just used to convert a plain parameter value)

objectName:String

the name of the target object

Method Detail

addBindValueback to summary
protected static void addBindValue(Map<String, Object> params, String key, List<?> values)
bindback to summary
public Mono<Void> bind(ServerWebExchange exchange)

Bind query parameters, form data, or multipart form data to the binder target.

Parameters
exchange:ServerWebExchange

the current exchange

Returns:Mono<Void>

a Mono<Void> that completes when binding is complete

constructback to summary
public Mono<Void> construct(ServerWebExchange exchange)

Use a default or single data constructor to create the target by binding request parameters, multipart files, or parts to constructor args.

After the call, use getBindingResult() to check for bind errors. If there are none, the target is set, and bind can be called for further initialization via setters.

Parameters
exchange:ServerWebExchange

the request to bind

Returns:Mono<Void>

a Mono<Void> that completes when the target is created

Since
6.1
extractValuesToBindback to summary
public static Mono<Map<String, Object>> extractValuesToBind(ServerWebExchange exchange)

Combine query params and form data for multipart form data from the body of the request into a Map<String, Object> of values to use for data binding purposes.

Parameters
exchange:ServerWebExchange

the current exchange

Returns:Mono<Map<String, Object>>

a Mono with the values to bind

See Also
org.springframework.http.server.reactive.ServerHttpRequest#getQueryParams(), ServerWebExchange#getFormData(), ServerWebExchange#getMultipartData()
getValuesToBindback to summary
public Mono<Map<String, Object>> getValuesToBind(ServerWebExchange exchange)

Obtain the values for data binding. By default, this delegates to extractValuesToBind(ServerWebExchange).

Parameters
exchange:ServerWebExchange

the current exchange

Returns:Mono<Map<String, Object>>

a map of bind values

Since
5.3
shouldConstructArgumentback to summary
protected boolean shouldConstructArgument(MethodParameter param)

Overrides org.springframework.validation.DataBinder.shouldConstructArgument.

Doc from org.springframework.validation.DataBinder.shouldConstructArgument.

Whether to instantiate the constructor argument of the given type, matching its own constructor arguments to bind values.

By default, simple value types, maps, collections, and arrays are excluded from nested constructor binding initialization.

Annotations
@Override
org.springframework.web.bind.support back to summary

private final Record WebExchangeDataBinder.MapValueResolver

extends Record
implements ValueResolver
Class Inheritance
All Implemented Interfaces
org.springframework.validation.DataBinder.ValueResolver
Record Components
map:Map<String, Object> 

Resolve values from a map.

Field Summary

Modifier and TypeField and Description
private final Map<String, Object>
map

Record Component accessed by map().

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object
the reference object with which to compare.
o
)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.
public Set<String>
getNames()

Implements org.springframework.validation.DataBinder.ValueResolver.getNames.

Return the names of all property values.
public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.
public Map<String, Object>
map()

Record Component getter of map.

public Object
resolveValue(String
the name to use for the lookup, possibly a nested path for constructor parameters on nested objects
name
,
Class<?>
the target type, based on the constructor parameter type
type
)

Implements org.springframework.validation.DataBinder.ValueResolver.resolveValue.

Resolve the value for the given name and target parameter type.
public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

mapback to summary
private final Map<String, Object> map

Record Component accessed by map().

Constructor Detail

MapValueResolverback to summary
private MapValueResolver(Map<String, Object> map)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this record is equal to the argument; false otherwise.

getNamesback to summary
public Set<String> getNames()

Implements org.springframework.validation.DataBinder.ValueResolver.getNames.

Doc from org.springframework.validation.DataBinder.ValueResolver.getNames.

Return the names of all property values.

Annotations
@Override
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

Returns:int

a hash code value for this record.

mapback to summary
public Map<String, Object> map()

Record Component getter of map.

resolveValueback to summary
public Object resolveValue(String name, Class<?> type)

Implements org.springframework.validation.DataBinder.ValueResolver.resolveValue.

Doc from org.springframework.validation.DataBinder.ValueResolver.resolveValue.

Resolve the value for the given name and target parameter type.

Parameters
name:String

the name to use for the lookup, possibly a nested path for constructor parameters on nested objects

type:Class<?>

the target type, based on the constructor parameter type

Returns:Object

the resolved value, possibly null if none found

Annotations
@Override
toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

Returns:String

a string representation of the object.