Skip to main content

@UrlEncoding Annotation

The URL-Encoding format provides two annotations for tailoring how beans are serialized and parsed: @UrlEncoding for per-bean overrides, and @UrlEncodingConfig for configuring REST classes and methods.

@UrlEncoding​

The @UrlEncoding annotation can be applied to classes, fields, and methods to override the behavior of UrlEncodingSerializer and UrlEncodingParser for individual beans.

UrlEncodingexpandedParams

The expandedParams setting forces bean properties of type array or Collection to be expanded into multiple key/value pairings rather than a single nested value. This is equivalent to the serializer/parser expandedParams() builder settings, but applies only to instances of the annotated bean.

// Expand array/collection properties into repeated key=value pairs for this bean only.
@UrlEncoding(expandedParams=true)
public class MyBean {
public int[] a = {1, 2, 3};
}

// Serializes to: a=1&a=2&a=3 (instead of a=@(1,2,3))
String urlencoded = UrlEncodingSerializer.DEFAULT.write(new MyBean());

@UrlEncodingConfig​

The @UrlEncodingConfig annotation applies the same configuration properties at the REST level — on @Rest-annotated classes and @RestOp-annotated methods:

@Rest(...)
@UrlEncodingConfig(expandedParams="true")
public class MyResource extends BasicRestServlet {
...
}

Its expandedParams attribute is a String (so it can carry an SVL variable such as "$C{myConfig}"), and a rank attribute can be used to control the order in which config annotations are applied.

note

When parsing multi-part parameters, prefer Collection/List bean property types over arrays — arrays must be recreated from scratch each time a value is added.

See also​