Package com.carfey.ops.job.result
Class SerializationFactory
- java.lang.Object
-
- com.carfey.ops.job.result.SerializationFactory
-
public class SerializationFactory extends java.lang.ObjectClass whereSerializationStrategyinstances 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 ofDefaultSerializationStrategyis registered, with an instance ofJsonSerializationStrategyregistered as second priority to handle serialization of complex types.- Since:
- 4.4
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearAll()Clears all registered strategies,.java.lang.ObjectdeserializeJobResult(java.lang.String name, java.lang.String strVal, java.lang.String type)Finds an appropriate strategy and deserializes with it.static SerializationFactoryget()java.util.List<SerializationStrategy>getStrategies()voidregister(SerializationStrategy strategy)Adds a single strategy at a lower priority than other registered strategies.voidreplaceAll(java.util.List<? extends SerializationStrategy> strategies)Replaces all registered strategies with the supplied list.voidreset()Resets the factory to its initial state, with aDefaultSerializationStrategyandJsonSerializationStrategyregistered.java.lang.StringserializeJobResult(java.lang.String name, java.lang.Object val)Finds an appropriate strategy and serializes with it.
-
-
-
Method Detail
-
get
public static SerializationFactory get()
- Returns:
- the singleton factory, which can be customized
-
reset
public void reset()
Resets the factory to its initial state, with aDefaultSerializationStrategyandJsonSerializationStrategyregistered.
-
clearAll
public void clearAll()
Clears all registered strategies,. Note that even after resetting, theDefaultSerializationStrategyis 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 ParameterExceptionFinds an appropriate strategy and deserializes with it. Falls back to theDefaultSerializationStrategyif no applicable strategy is registered.- Parameters:
name- result namestrVal- string representationtype- 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 ParameterExceptionFinds an appropriate strategy and serializes with it. Falls back to theDefaultSerializationStrategyif no applicable strategy is registered.- Parameters:
name- result nameval- value to serialize- Returns:
- string representation
- Throws:
ParameterException- on any failure
-
-