Fix #652: Apply a class adapter to values of a type known at runtime A value whose type is only known at runtime, such as an element of a raw collection or of List.of(...), is serialized with the customization of its declared type, Object. An adapter declared with @JsonbTypeAdapter on the class of the value was therefore not found, the value was serialized as a plain object, and that serializer was cached for the class, so even a later toJson() of the value itself ignored the adapter. When the customization of the declared type binds no serializer or adapter, take them from the customization of the runtime class. Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
Yasson is a Java framework which provides a standard binding layer between Java classes and JSON documents. This is similar to what JAXB is doing in the XML world. Yasson is an official reference implementation of JSON Binding (JSR-367).
It defines a default mapping algorithm for converting existing Java classes to JSON suitable for the most cases:
Jsonb jsonb = JsonbBuilder.create(); String result = jsonb.toJson(someObject);
For whom it's not enough it provides rich customization abilities through a set of annotations and rich programmatic API:
// Create custom configuration JsonbConfig config = new JsonbConfig() .withNullValues(true) .withFormatting(true); // Create Jsonb with custom configuration Jsonb jsonb = JsonbBuilder.create(config); // Use it! String result = jsonb.toJson(someObject);
Something not working right? Have an idea for an enhancement? Get in touch with the Yasson community in the following ways:
[jsonb-api] and [yasson]