DataConversion is a feature that allows to serialize and deserialize a list of values.
By default, it handles primitive types and enums, but it can also be configured to handle additional types.
If you are using the Locations feature and want to support custom types as part of its parameters, you can add new custom converters with this service.
Installing the DataConversion is pretty easy, and it should be cover primitive types:
The DataConversion configuration, provide a
convert<T> method to define type conversions. Inside, you have to provide a decoder and an encoder with the
encode methods accepting callbacks.
converter: (values: List<String>, type: Type) -> Any?Accepts
values, a list of strings) representing repeated values in the URL, for example,
a=1&a=2, and accepts the
typeto convert to. It should return the decoded value.
converter: (value: Any?) -> List<String>Accepts an arbitrary value, and should return a list of strings representing the value. When returning a list of a single element, it will be serialized as
key=item1. For multiple values, it will be serialized in the query string as:
Another potential use is to customize how a specific enum is serialized. By default enums are serialized and de-serialized using its
.name in a case-sensitive fashion. But you can for example serialize them as lower case and deserialize them in a case-insensitive fashion:
Accessing the service
You can easily access the DataConversion service, from any call with: