java.lang.Object
io.inverno.mod.base.converter.CompositeEncoder<To>
- Type Parameters:
To
- the encoded type
A composite encoder relies on multiple CompoundEncoder
to encode
objects.
Such implementation makes it possible to create extensible encoder able to encode various type of objects by composition of many specific compound encoders.
- Since:
- 1.0
- Author:
- Jeremy Kuhn
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<T> To
encode
(T value) Encodes the specified value to the encoded type.<T> To
Encodes the specified value whose type is represented by the specified class to the encoded type.<T> To
Encodes the specified value whose type is the specified type to the encoded type.protected <T> CompoundEncoder
<T, To> getEncoder
(Type type) Returns the first compound encoder that can encode the specified type.void
setDefaultEncoder
(Encoder<Object, To> defaultEncoder) Sets a default encoder to use when no compound encoder is able to encode an object.void
setEncoders
(List<CompoundEncoder<?, To>> encoders) Sets the compound encoders used to encode objects.
-
Constructor Details
-
CompositeEncoder
public CompositeEncoder()Creates a composite encoder.
-
-
Method Details
-
setEncoders
Sets the compound encoders used to encode objects.
- Parameters:
encoders
- a list of compound encoders
-
setDefaultEncoder
Sets a default encoder to use when no compound encoder is able to encode an object.
- Parameters:
defaultEncoder
- the default decoder
-
getEncoder
Returns the first compound encoder that can encode the specified type.
- Type Parameters:
T
- the type of object encoded by the returned encoder- Parameters:
type
- the type to encode- Returns:
- a compound encoder
- Throws:
EncoderNotFoundException
- if no encoder can encode the specified type
-
encode
Description copied from interface:Encoder
Encodes the specified value to the encoded type.
- Specified by:
encode
in interfaceEncoder<Object,
To> - Type Parameters:
T
- the type of the decoded object- Parameters:
value
- the object to encode- Returns:
- an encoded object
- Throws:
EncoderNotFoundException
-
encode
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 interfaceEncoder<Object,
To> - Type Parameters:
T
- the type of the decoded object- Parameters:
value
- the object to encodetype
- the class of the decoded object- Returns:
- an encoded object
- Throws:
ConverterException
- if there was an error encoding the value
-
encode
Description copied from interface:Encoder
Encodes the specified value whose type is the specified type to the encoded type.
- Specified by:
encode
in interfaceEncoder<Object,
To> - Type Parameters:
T
- the type of the decoded object- Parameters:
value
- the object to encodetype
- the type of the decoded object- Returns:
- an encoded object
- Throws:
ConverterException
- if there was an error encoding the value
-