serialization
Serialization in UCloud is provided by the jackson library. We use the following modules, on top of the core jackson module:
A jackson mapper is available in service-lib
and is exported as defaultMapper
in the dk.sdu.cloud
package. The defaultMapper
uses JSON
as its data format. This mapper uses the following configuration:
Config | Description |
---|---|
| Don't fail if an ignored property is encountered |
| Don't fail if a new property is introduced in the API |
| Provides flexibility in terms of compatibility |
| Provides flexibility in terms of compatibility |
| Provides flexibility in terms of compatibility |
The reason for this configuration is to be as relaxed as possible in order to improve backwards-compatibility.
Sealed Classes
For a variety of reasons, including security, is generally not recommended that you use large class-hierarchies for request/response types. The one exception to this rule is sealed classes. This introduces a problem on the client-side of how to determine the correct type. To solve this problem, you must add annotations to the sealed class which tell Jackson to annotate the resulting JSON with a new key-value pair which include a type-hint.
Examples
Example: Using sealed classes with Jackson
Example: Using the defaultMapper
instance to parse a JSON object
Example: Using the defaultMapper
instance to serialize an object to JSON
Last updated