From 8ce420e5e86476e1847b5eb68950708166f93c09 Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Wed, 10 May 2023 16:53:02 +0200 Subject: [PATCH] Update jsonb.adoc - Annotate adapter on a class It would be rather comfortable if we could allow to annotate any POJO with `@JsonbTypeAdapter`, so ANY use of that POJO in ANY location (as field content, in collections, as keys or values in maps) would trigger the use of the named adapter class. --- spec/src/main/asciidoc/jsonb.adoc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/src/main/asciidoc/jsonb.adoc b/spec/src/main/asciidoc/jsonb.adoc index a21b7c97..8a170a72 100644 --- a/spec/src/main/asciidoc/jsonb.adoc +++ b/spec/src/main/asciidoc/jsonb.adoc @@ -733,13 +733,14 @@ On serialization of Original type JSONB calls `JsonbAdapter::adaptToJson` method On deserialization JSONB deserializes Adapted from JSON and converts it to Original using `JsonbAdapter::adaptFromJson` method. -There are two ways how to register `JsonbAdapter`: +There are three ways how to register `JsonbAdapter`: [arabic] . Using `JsonbConfig::withAdapters` method; . Annotating a class field with `JsonbTypeAdapter` annotation. +. Annotating a type with `JsonbTypeAdapter` annotation. -`JsonbAdapter` registered via `JsonbConfig::withAdapters` is visible to all serialize/deserialize operations performed with given `JsonbConfig`. `JsonbAdapter` registered with annotation is visible to serialize/deserialize operation used only for annotated field. +`JsonbAdapter` registered via `JsonbConfig::withAdapters` is visible to all serialize/deserialize operations performed with given `JsonbConfig`. `JsonbAdapter` registered with annotation on a *field* is visible to serialize/deserialize operation used only for annotated field. `JsonbAdapter` registered with annotation on a *class* is visible to all serialize/deserialize operations of the annotated class. It is possible to annotate `JsonbCreator` parameter with `JsonbTypeAdapter` and provide adapter for a parameter this way. However, if `JsonbTypeAdapter` annotation is provided to any other parameter (such as setter method parameter) it will be ignored.