Class JsonbPolymorphismHandler
- java.lang.Object
-
- org.apache.johnzon.jsonb.polymorphism.JsonbPolymorphismHandler
-
public class JsonbPolymorphismHandler extends Object
-
-
Field Summary
Fields Modifier and Type Field Description private Map<Class<?>,JsonbPolymorphismTypeInfo>
typeInfoCache
-
Constructor Summary
Constructors Constructor Description JsonbPolymorphismHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonbPolymorphismTypeInfo
getOrCreatePolymorphismTypeInfo(Class<?> clazz)
Looks up aJsonbPolymorphismTypeInfo
from the cache or creates it for the givenclazz
if it supports polymorphism.Map.Entry<String,String>[]
getPolymorphismPropertiesToSerialize(Class<?> clazz, Collection<String> otherProperties)
Class<?>
getTypeToDeserialize(jakarta.json.JsonObject jsonObject, Class<?> clazz)
boolean
hasPolymorphism(Class<?> clazz)
void
validateJsonbPolymorphismAnnotations(Class<?> classToValidate)
ValidatesJsonbTypeInfo
annotation on clazz and its parents (superclass/interfaces), seevalidateSubtypeCompatibility(Class)
,validateOnlyOneParentWithTypeInfo(Class)
andvalidateNoTypeInfoKeyCollision(Class)
protected void
validateNoTypeInfoKeyCollision(Class<?> classToValidate)
Validates thatJsonbTypeInfo.key()
is only defined once in type hierarchy.protected void
validateOnlyOneParentWithTypeInfo(Class<?> classToValidate)
Validates that only one parent class (superclass + interfaces) hasJsonbTypeInfo
annotationprotected void
validateSubtypeCompatibility(Class<?> classToValidate)
Validation fails if any clazz andJsonbSubtype.type()
aren't compatible.
-
-
-
Field Detail
-
typeInfoCache
private final Map<Class<?>,JsonbPolymorphismTypeInfo> typeInfoCache
-
-
Method Detail
-
hasPolymorphism
public boolean hasPolymorphism(Class<?> clazz)
-
getPolymorphismPropertiesToSerialize
public Map.Entry<String,String>[] getPolymorphismPropertiesToSerialize(Class<?> clazz, Collection<String> otherProperties)
-
getTypeToDeserialize
public Class<?> getTypeToDeserialize(jakarta.json.JsonObject jsonObject, Class<?> clazz)
-
getOrCreatePolymorphismTypeInfo
public JsonbPolymorphismTypeInfo getOrCreatePolymorphismTypeInfo(Class<?> clazz)
Looks up aJsonbPolymorphismTypeInfo
from the cache or creates it for the givenclazz
if it supports polymorphism. This is the case if either one of these conditions is truthy:clazz
has anJsonbTypeInfo
annotation- any class in the type hierarchy of
clazz
has anJsonbTypeInfo
annotation
- Parameters:
clazz
- Class to inspect- Returns:
JsonbPolymorphismTypeInfo
if the class supports polymorphism,null
otherwise
-
validateJsonbPolymorphismAnnotations
public void validateJsonbPolymorphismAnnotations(Class<?> classToValidate)
ValidatesJsonbTypeInfo
annotation on clazz and its parents (superclass/interfaces), seevalidateSubtypeCompatibility(Class)
,validateOnlyOneParentWithTypeInfo(Class)
andvalidateNoTypeInfoKeyCollision(Class)
- Parameters:
classToValidate
- Class to validate- Throws:
jakarta.json.bind.JsonbException
- validation failed
-
validateSubtypeCompatibility
protected void validateSubtypeCompatibility(Class<?> classToValidate)
Validation fails if any clazz andJsonbSubtype.type()
aren't compatible.- Parameters:
classToValidate
- Class to validate- Throws:
jakarta.json.bind.JsonbException
- validation failed
-
validateOnlyOneParentWithTypeInfo
protected void validateOnlyOneParentWithTypeInfo(Class<?> classToValidate)
Validates that only one parent class (superclass + interfaces) hasJsonbTypeInfo
annotation- Parameters:
classToValidate
- class to validate- Throws:
jakarta.json.bind.JsonbException
- validation failed
-
validateNoTypeInfoKeyCollision
protected void validateNoTypeInfoKeyCollision(Class<?> classToValidate)
Validates thatJsonbTypeInfo.key()
is only defined once in type hierarchy. AssumesvalidateOnlyOneParentWithTypeInfo(Class)
already passed.- Parameters:
classToValidate
- class to validate- Throws:
jakarta.json.bind.JsonbException
- validation failed
-
-