Interface Serialiser<INPUT,​OUTPUT>

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean canHandle​(Class clazz)
      Check whether the serialiser can serialise a particular class.
      INPUT deserialise​(OUTPUT output)
      Deserialise an OUTPUT into the original object.
      INPUT deserialiseEmpty()
      Handle an empty OUTPUT and reconstruct an appropriate representation in Object form.
      boolean isConsistent()
      Indicates whether the serialisation process produces a predictable, consistent OUTPUT, from a given INPUT, ie the same object should always serialise in the same way for this to be true.
      boolean preservesObjectOrdering()
      Indicates whether the serialisation process preserves the ordering of the INPUT, i.e.
      OUTPUT serialise​(INPUT object)
      Serialise some object and returns the OUTPUT of the serialised form.
      OUTPUT serialiseNull()
      Handle an incoming null value and generate an appropriate OUTPUT representation.
    • Method Detail

      • serialiseNull

        OUTPUT serialiseNull()
        Handle an incoming null value and generate an appropriate OUTPUT representation.
        Returns:
        OUTPUT the serialised output
      • canHandle

        boolean canHandle​(Class clazz)
        Check whether the serialiser can serialise a particular class.

        //Warning: Due to erasure you may get false positives. e.g.

         
         Set<Foo> set = Sets.newHashSet();
         boolean b = new Serialiser<Set<Bar>, byte[]>().canHandle(set.getClass());
         b will incorrectly be true because of type erasure between Set<Foo> Set<Bar>
         
         
        Parameters:
        clazz - the object class to serialise
        Returns:
        boolean true if it can be handled
      • serialise

        OUTPUT serialise​(INPUT object)
                  throws SerialisationException
        Serialise some object and returns the OUTPUT of the serialised form.
        Parameters:
        object - the object to be serialised
        Returns:
        OUTPUT the serialised OUTPUT
        Throws:
        SerialisationException - if the object fails to serialise
      • deserialise

        INPUT deserialise​(OUTPUT output)
                   throws SerialisationException
        Deserialise an OUTPUT into the original object.
        Parameters:
        output - the OUTPUT to deserialise
        Returns:
        INPUT the deserialised object
        Throws:
        SerialisationException - if the object fails to deserialise
      • deserialiseEmpty

        INPUT deserialiseEmpty()
                        throws SerialisationException
        Handle an empty OUTPUT and reconstruct an appropriate representation in Object form.
        Returns:
        INPUT the deserialised object
        Throws:
        SerialisationException - if the object fails to deserialise
      • preservesObjectOrdering

        boolean preservesObjectOrdering()
        Indicates whether the serialisation process preserves the ordering of the INPUT, i.e. if x and y are objects of class INPUT, and x is less than y, then this method should return true if the serialised form of x is guaranteed to be less than the serialised form of y (using the standard ordering of OUTPUT). If INPUT is not Comparable then this test makes no sense and false should be returned.
        Returns:
        true if the serialisation will preserve the order of the INPUT, otherwise false.
      • isConsistent

        boolean isConsistent()
        Indicates whether the serialisation process produces a predictable, consistent OUTPUT, from a given INPUT, ie the same object should always serialise in the same way for this to be true.
        Returns:
        true if serialisation is consistent for a given object, otherwise false.