Interface ValueSerialiser<T>

Type Parameters:
T - the target type of deserialisation
All Known Implementing Classes:
URLValueSerialiser

public interface ValueSerialiser<T>
Functional interface for serialising and deserialising configuration entries.

It should always be the case that if deserialisation succeeds, serialising the same value should succeed. That is, deserialise and serialise should be inverse operations.
Author:
A248
  • Method Summary

    Modifier and Type
    Method
    Description
    deserialise​(FlexibleType flexibleType)
    Deserialises a value from a flexible type representing a raw config value.
    Gets the target type of deserialisation
    serialise​(T value, Decomposer decomposer)
    Serialises a value to a raw config value.
  • Method Details

    • getTargetClass

      Class<T> getTargetClass()
      Gets the target type of deserialisation
      Returns:
      the target class type
    • deserialise

      T deserialise(FlexibleType flexibleType) throws BadValueException
      Deserialises a value from a flexible type representing a raw config value.

      The key (FlexibleType.getAssociatedKey()) is informative. It should not affect the deserialisation, but should be included in thrown BadValueExceptions to inform the user which key is in question.
      Parameters:
      flexibleType - the flexible type
      Returns:
      the deserialised value, never null
      Throws:
      BadValueException - if the value could not be deserialised
    • serialise

      Object serialise(T value, Decomposer decomposer)
      Serialises a value to a raw config value. Should be the inverse operation of deserialise(FlexibleType) in that if the result of this method were wrapped in a FlexibleType, it could be deserialised.

      If this serialiser serialises values by converting from another custom type, then the provided decomposer should be used to reserialise such custom types.
      Parameters:
      value - the value
      decomposer - the decomposer used to help breakdown the value
      Returns:
      the serialised value