Class CompositeConverter<A>

java.lang.Object
io.inverno.mod.base.converter.CompositeConverter<A>
Type Parameters:
A - the converted type
All Implemented Interfaces:
Converter<A,Object>, Decoder<A,Object>, Encoder<Object,A>
Direct Known Subclasses:
StringCompositeConverter

public class CompositeConverter<A> extends Object implements Converter<A,Object>

A composite converter relies on multiple CompoundEncoder and CompoundDecoder to convert objects.

Such implementation makes it possible to create extensible converter able to convert various type of objects by composition of many specific compound encoders and decoders.

Since:
1.0
Author:
Jeremy Kuhn
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a composite converter.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    decode(A value, Class<T> type)
    Decodes the specified value to an object whose type is represented by the specified class.
    <T> T
    decode(A value, Type type)
    Decodes the specified value to an object of the specified type.
    <T> A
    encode(T value)
    Encodes the specified value to the encoded type.
    <T> A
    encode(T value, Class<T> type)
    Encodes the specified value whose type is represented by the specified class to the encoded type.
    <T> A
    encode(T value, Type type)
    Encodes the specified value whose type is the specified type to the encoded type.
    void
    Sets the compound decoders used to decode objects.
    void
    setDefaultDecoder(Decoder<A,Object> defaultDecoder)
    Sets a default decoder to use when no compound decoder is able to decode an object.
    void
    setDefaultEncoder(Encoder<Object,A> defaultEncoder)
    Sets a default encoder to use when no compound encoder is able to encode an object.
    void
    Sets the compound encoders used to encode objects.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CompositeConverter

      public CompositeConverter()

      Creates a composite converter.

  • Method Details

    • setDecoders

      public void setDecoders(List<CompoundDecoder<A,?>> decoders)

      Sets the compound decoders used to decode objects.

      Parameters:
      decoders - a list of compound decoders
    • setEncoders

      public void setEncoders(List<CompoundEncoder<?,A>> encoders)

      Sets the compound encoders used to encode objects.

      Parameters:
      encoders - a list of compound encoders
    • setDefaultDecoder

      public void setDefaultDecoder(Decoder<A,Object> defaultDecoder)

      Sets a default decoder to use when no compound decoder is able to decode an object.

      Parameters:
      defaultDecoder - the default decoder
    • setDefaultEncoder

      public void setDefaultEncoder(Encoder<Object,A> defaultEncoder)

      Sets a default encoder to use when no compound encoder is able to encode an object.

      Parameters:
      defaultEncoder - the default decoder
    • decode

      public <T> T decode(A value, Class<T> type)
      Description copied from interface: Decoder

      Decodes the specified value to an object whose type is represented by the specified class.

      Specified by:
      decode in interface Decoder<A,Object>
      Type Parameters:
      T - the type of the decoded object
      Parameters:
      value - the object to decode
      type - the class of the decoded object
      Returns:
      a decoded object
    • decode

      public <T> T decode(A value, Type type) throws ConverterException
      Description copied from interface: Decoder

      Decodes the specified value to an object of the specified type.

      Specified by:
      decode in interface Decoder<A,Object>
      Type Parameters:
      T - the type of the decoded object
      Parameters:
      value - the object to decode
      type - the type of the decoded object
      Returns:
      a decoded object
      Throws:
      ConverterException - if there was an error decoding the value
    • encode

      public <T> A encode(T value)
      Description copied from interface: Encoder

      Encodes the specified value to the encoded type.

      Specified by:
      encode in interface Encoder<Object,A>
      Type Parameters:
      T - the type of the decoded object
      Parameters:
      value - the object to encode
      Returns:
      an encoded object
    • encode

      public <T> A encode(T value, Class<T> type) throws ConverterException
      Description copied from interface: Encoder

      Encodes the specified value whose type is represented by the specified class to the encoded type.

      Specified by:
      encode in interface Encoder<Object,A>
      Type Parameters:
      T - the type of the decoded object
      Parameters:
      value - the object to encode
      type - the class of the decoded object
      Returns:
      an encoded object
      Throws:
      ConverterException - if there was an error encoding the value
    • encode

      public <T> A encode(T value, Type type) throws ConverterException
      Description copied from interface: Encoder

      Encodes the specified value whose type is the specified type to the encoded type.

      Specified by:
      encode in interface Encoder<Object,A>
      Type Parameters:
      T - the type of the decoded object
      Parameters:
      value - the object to encode
      type - the type of the decoded object
      Returns:
      an encoded object
      Throws:
      ConverterException - if there was an error encoding the value