Class CompositeDecoder<From>

java.lang.Object
io.inverno.mod.base.converter.CompositeDecoder<From>
Type Parameters:
From - the decoded type
All Implemented Interfaces:
Decoder<From,Object>

public class CompositeDecoder<From> extends Object implements Decoder<From,Object>

A composite decoder relies on multiple CompoundDecoder to decode objects.

Such implementation makes it possible to create extensible decoder able to decode various type of objects by composition of many specific compound decoders.

Since:
1.0
Author:
Jeremy Kuhn
  • Constructor Details

    • CompositeDecoder

      public CompositeDecoder()

      Creates a composite decoder.

  • Method Details

    • setDecoders

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

      Sets the compound decoders used to decode objects.

      Parameters:
      decoders - a list of compound decoders
    • setDefaultDecoder

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

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

      Parameters:
      defaultDecoder - the default decoder
    • getDecoder

      protected <T> CompoundDecoder<From,T> getDecoder(Type type)

      Returns the first compound decoder that can decode the specified type.

      Type Parameters:
      T - the type of object decoded by the returned decoder
      Parameters:
      type - the type to decode
      Returns:
      a compound decoder
      Throws:
      DecoderNotFoundException - if no decoder can decode the specified type
    • decode

      public <T> T decode(From value, Class<T> type) throws DecoderNotFoundException
      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<From,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
      Throws:
      DecoderNotFoundException
    • decode

      public <T> T decode(From 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<From,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