Class TypeMapper
java.lang.Object
org.gcube.informationsystem.types.TypeMapper
A utility class for mapping between Java classes and
Type definitions,
and for serializing/deserializing these definitions to/from JSON.- Author:
- Luca Frosini (ISTI - CNR)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.gcube.com.fasterxml.jackson.databind.ObjectMapperThe object mapper. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateTypeDefinition(Class<E> clz) static TypeDeserializes aTypedefinition from a JSON string.Deserializes a list ofTypedefinitions from a JSON string.getDynamicImplementation(Class<E> clz) Gets the dynamic implementation class for a given interface, if specified via theDeserializeannotation.getType(E e) Returns the type name of anElementinstance.static StringReturns the type name of anElementclass, derived from annotations.getTypeChangelog(Class<? extends Element> clz) static StringgetTypeDescription(Class<? extends Element> clz) Returns the description of anElementclass from itsTypeMetadata.static VersiongetTypeVersion(Class<? extends Element> clz) Returns the version of anElementclass from itsTypeMetadata.serializeType(Class<E> clz) static StringserializeTypeDefinition(Type type) Serializes aTypedefinition to a JSON string.static StringserializeTypeDefinitions(List<Type> typeDefinitions) Serializes a list ofTypedefinitions to a JSON string.
-
Field Details
-
mapper
protected static final org.gcube.com.fasterxml.jackson.databind.ObjectMapper mapperThe object mapper.
-
-
Constructor Details
-
TypeMapper
public TypeMapper()
-
-
Method Details
-
serializeTypeDefinition
Serializes aTypedefinition to a JSON string.- Parameters:
type- The type definition.- Returns:
- The JSON string.
- Throws:
Exception- if an error occurs during serialization.
-
deserializeTypeDefinition
Deserializes aTypedefinition from a JSON string.- Parameters:
json- The JSON string.- Returns:
- The deserialized type definition.
- Throws:
Exception- if an error occurs during deserialization.
-
serializeTypeDefinitions
Serializes a list ofTypedefinitions to a JSON string.- Parameters:
typeDefinitions- The list of type definitions.- Returns:
- The JSON string.
- Throws:
Exception- if an error occurs during serialization.
-
deserializeTypeDefinitions
Deserializes a list ofTypedefinitions from a JSON string.- Parameters:
json- The JSON string.- Returns:
- The deserialized list of type definitions.
- Throws:
Exception- if an error occurs during deserialization.
-
createTypeDefinition
- Type Parameters:
E- The type of the element.- Parameters:
clz- The element class.- Returns:
- The generated type definition.
-
serializeType
- Type Parameters:
E- The type of the element.- Parameters:
clz- The element class.- Returns:
- The JSON string representation of the type.
- Throws:
Exception- if an error occurs during serialization.
-
getType
Returns the type name of anElementinstance.- Type Parameters:
E- The type of the element.- Parameters:
e- The element instance.- Returns:
- The type name.
-
getDynamicImplementation
public static <E extends Element,EImpl extends E> Class<EImpl> getDynamicImplementation(Class<E> clz) Gets the dynamic implementation class for a given interface, if specified via theDeserializeannotation.- Type Parameters:
E- The type of the element.EImpl- The type of the implementation.- Parameters:
clz- The interface class.- Returns:
- The implementation class, or
null.
-
getType
Returns the type name of anElementclass, derived from annotations.- Parameters:
clz- The element class.- Returns:
- The type name.
-
getTypeDescription
Returns the description of anElementclass from itsTypeMetadata.- Parameters:
clz- The element class.- Returns:
- The type description.
-
getTypeVersion
Returns the version of anElementclass from itsTypeMetadata.- Parameters:
clz- The element class.- Returns:
- The type version.
-
getTypeChangelog
- Parameters:
clz- The element class.- Returns:
- A map of versions to change descriptions.
-