Class SerializationFactory


  • public class SerializationFactory
    extends java.lang.Object
    Class where SerializationStrategy instances can be registered for use in storing and retrieving Obsidian job results. Note that ordering of strategies is relevant since the first one to support the type of object to be serialized will be used. By default, an instance of DefaultSerializationStrategy is registered, with an instance of JsonSerializationStrategy registered as second priority to handle serialization of complex types.
    Since:
    4.4
    • Method Detail

      • get

        public static SerializationFactory get()
        Returns:
        the singleton factory, which can be customized
      • clearAll

        public void clearAll()
        Clears all registered strategies,. Note that even after resetting, the DefaultSerializationStrategy is still used as a fallback when no other strategies are registered.
      • register

        public void register​(SerializationStrategy strategy)
        Adds a single strategy at a lower priority than other registered strategies.
      • replaceAll

        public void replaceAll​(java.util.List<? extends SerializationStrategy> strategies)
        Replaces all registered strategies with the supplied list. The order of the list indicates the priority in which strategies are selected and applied.
      • getStrategies

        public java.util.List<SerializationStrategy> getStrategies()
        Returns:
        a read-only view of the registered strategies.
      • deserializeJobResult

        public java.lang.Object deserializeJobResult​(java.lang.String name,
                                                     java.lang.String strVal,
                                                     java.lang.String type)
                                              throws ParameterException
        Finds an appropriate strategy and deserializes with it. Falls back to the DefaultSerializationStrategy if no applicable strategy is registered.
        Parameters:
        name - result name
        strVal - string representation
        type - Java FQCN
        Returns:
        the deserialized result
        Throws:
        ParameterException - on any failures
      • serializeJobResult

        public java.lang.String serializeJobResult​(java.lang.String name,
                                                   java.lang.Object val)
                                            throws ParameterException
        Finds an appropriate strategy and serializes with it. Falls back to the DefaultSerializationStrategy if no applicable strategy is registered.
        Parameters:
        name - result name
        val - value to serialize
        Returns:
        string representation
        Throws:
        ParameterException - on any failure