You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spec/src/main/asciidoc/jsonb.adoc
+10-15Lines changed: 10 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -318,27 +318,22 @@ Deserialization into anonymous classes is not supported. Serialization of anonym
318
318
319
319
=== Polymorphic Types
320
320
321
-
Polymorphic type handling is supported for deserialization and serialization. Polymorphic handling is ensured by annotation `@JsonbPolymorphicType` and `@JsonbSubtype`. `@JsonbPolymorphicType` defines how the overall polymorphic information strategy will be serialized/deserialized and defines all the supported aliases using `@JsonbSubtype` annotations. `@JsonbSubtype` ensures proper and safe mapping between class alias and type. Implementation must validate mapped types if they are assignable from the annotated type. If not, an exception must be thrown.
321
+
Polymorphic type handling is supported for deserialization and serialization. Polymorphic handling is ensured by annotation `JsonbTypeInfo` and `@JsonbSubtype`. `JsonbTypeInfo` defines key name of the property to store type information in it and defines all the supported aliases using `@JsonbSubtype` annotations. `@JsonbSubtype` ensures proper and safe mapping between class alias and type. Implementation must validate mapped types if they are assignable from the annotated type. If not, an exception must be thrown.
322
322
323
-
Polymorphic information is obtained from `@JsonbSubtype` annotation as a type alias mapped to the type or if `classNames` property of the `@JsonbPolymorphicType` is enabled, it corresponds to the fully qualified class name, if no suitable alias is found. Implementation must ensure to support `allowedPackages` option of the `@JsonbPolymorphicType` which is only used when `classNames` option is enabled, it is ignored otherwise. It is not allowed to create instances of the classes outside the allowed packages. In such cases an exception must be thrown. It is also required to have `allowedPackages` option set if `classNames` option is enabled. If the `allowedPackages` is null or empty an exception must be thrown.
323
+
Type information is obtained from `@JsonbSubtype` annotation as a type alias mapped to the type. If no matching class is found for obtained alias during deserialization, an exception must be thrown.
324
324
325
-
Available serialization formats:
325
+
New property with type information is added to the serialized object. The property key name is taken from the `key` property of the annotation `JsonbTypeInfo`. This type information property key name has to be unique in the resulting JSON document. If any naming collision with class or any other `JsonbTypeInfo` properties occurs, an exception must be thrown. It is required for all polymorphism fields to be serialized as the first properties in the JSON and any actual object properties are serialized after.
326
326
327
-
* Property - new property with polymorphic information is added to the serialized object. The property key name is taken from the `key` property of the annotation `@JsonbPolymorphicType`. This polymorphic information property key name has to be unique in the resulting JSON document. If any naming collision with class properties occurs, an exception must be thrown. It is required for all polymorphism fields to be serialized as the first properties in the JSON and any actual object properties are serialized after.
328
-
* Wrapping object - serialized object is wrapped with another object with a single property. The key corresponds to the polymorphic information of the type and the value is the serialized object
327
+
If no `JsonbTypeInfo` is used on handled class or its predecessors, it is not possible to ensure proper polymorphic type handling and in such cases deserialization is not supported.
329
328
330
-
If no `@JsonbPolymorphicType` is used on handled class or its predecessors, it is not possible to ensure proper polymorphic handling and in such cases deserialization is not supported for polymorphic types.
331
-
332
-
If the type predecessor has set `@JsonbPolymorphicType` and the current type also, but with the different format, an exception must be thrown.
333
-
334
-
If there are multiple different polymorphic customizations that need to be merged, an exception must be thrown. For example, if class has a predecessor with `@JsonbPolymorphicType` and one of its interfaces also has `@JsonbPolymorphicType` set, or two or more interfaces do have `@JsonbPolymorphicType` set, then an exception must be thrown.
329
+
If there are multiple different type polymorphic customizations that need to be merged, an exception must be thrown. Multiple inheritance of this customization is not supported.
335
330
336
331
[source,java]
337
332
----
338
-
@JsonbPolymorphicType({...})
333
+
@JsonbTypeInfo({...})
339
334
interface Vehicle {}
340
335
341
-
@JsonbPolymorphicType({...})
336
+
@JsonbTypeInfo({...})
342
337
interface Machine {}
343
338
344
339
class Car implements Vehicle, Machine {}
@@ -347,15 +342,15 @@ class Car implements Vehicle, Machine {}
347
342
In case of the following example:
348
343
[source,java]
349
344
----
350
-
@JsonbPolymorphicType(key = "@vehicle", value = {@JsonbSubtype(alias = "car", type = Car.class)})
345
+
@JsonbTypeInfo(key = "@vehicle", value = {@JsonbSubtype(alias = "car", type = Car.class)})
351
346
class Vehicle {...}
352
347
353
-
@JsonbPolymorphicType(key = "@car", value = {@JsonbSubtype(alias = "myCar", type = MyCar.class)})
348
+
@JsonbTypeInfo(key = "@car", value = {@JsonbSubtype(alias = "myCar", type = MyCar.class)})
354
349
class Car extends Vehicle {...}
355
350
356
351
class MyCar extends Car {...}
357
352
----
358
-
No exception is thrown since there is just one parent `@JsonbPolymorphicType` and one on the currently handled type. The order of the polymorphic information properties must be the same in which they appear in the polymorphic definition chain. Resulting JSON when serializing MyCar class would look like this:
353
+
The order of the type information properties must be the same in which they appear in the polymorphic type chain. Resulting JSON when serializing MyCar class would look like this:
0 commit comments