Class TypeMapper

java.lang.Object
org.gcube.informationsystem.types.TypeMapper

public class TypeMapper extends Object
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 Details

    • mapper

      protected static final org.gcube.com.fasterxml.jackson.databind.ObjectMapper mapper
      The object mapper.
  • Constructor Details

    • TypeMapper

      public TypeMapper()
  • Method Details

    • serializeTypeDefinition

      public static String serializeTypeDefinition(Type type) throws Exception
      Serializes a Type definition to a JSON string.
      Parameters:
      type - The type definition.
      Returns:
      The JSON string.
      Throws:
      Exception - if an error occurs during serialization.
    • deserializeTypeDefinition

      public static Type deserializeTypeDefinition(String json) throws Exception
      Deserializes a Type definition from a JSON string.
      Parameters:
      json - The JSON string.
      Returns:
      The deserialized type definition.
      Throws:
      Exception - if an error occurs during deserialization.
    • serializeTypeDefinitions

      public static String serializeTypeDefinitions(List<Type> typeDefinitions) throws Exception
      Serializes a list of Type definitions to a JSON string.
      Parameters:
      typeDefinitions - The list of type definitions.
      Returns:
      The JSON string.
      Throws:
      Exception - if an error occurs during serialization.
    • deserializeTypeDefinitions

      public static List<Type> deserializeTypeDefinitions(String json) throws Exception
      Deserializes a list of Type definitions 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

      public static <E extends Element> Type createTypeDefinition(Class<E> clz)
      Creates a Type definition from a given Element class.
      Type Parameters:
      E - The type of the element.
      Parameters:
      clz - The element class.
      Returns:
      The generated type definition.
    • serializeType

      public static <E extends Element> String serializeType(Class<E> clz) throws Exception
      Serializes the Type definition of a given Element class to JSON.
      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

      public static <E extends Element> String getType(E e)
      Returns the type name of an Element instance.
      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 the Deserialize annotation.
      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

      public static String getType(Class<? extends Element> clz)
      Returns the type name of an Element class, derived from annotations.
      Parameters:
      clz - The element class.
      Returns:
      The type name.
    • getTypeDescription

      public static String getTypeDescription(Class<? extends Element> clz)
      Returns the description of an Element class from its TypeMetadata.
      Parameters:
      clz - The element class.
      Returns:
      The type description.
    • getTypeVersion

      public static Version getTypeVersion(Class<? extends Element> clz)
      Returns the version of an Element class from its TypeMetadata.
      Parameters:
      clz - The element class.
      Returns:
      The type version.
    • getTypeChangelog

      public static Map<Version,String> getTypeChangelog(Class<? extends Element> clz)
      Returns the changelog of an Element class from its Changelog annotation.
      Parameters:
      clz - The element class.
      Returns:
      A map of versions to change descriptions.