saker.build Documentation TaskDoc JavaDoc
public interface DataConverter
Interface for specializing type conversion.

Implementations are provided with a conversion context, and an object, to execute conversion to the target type.

This interface is usually used with conjunction of the ConverterConfiguration interface. It can be used to specialize the conversion mechanism of DataConverterUtils.

Implementations of this interface should have a public no-arg constructor.

The DataConverter classes are stateless, meaning, if they are called with the same arguments they will return the same results. They may be cached to avoid construction of multiple objects.

Methods
public Object
convert(ConversionContext conversioncontext, Object value, Type targettype)
Converts the argument object to the target type.
public abstract Object convert(ConversionContext conversioncontext, Object value, Type targettype) throws ConversionFailedException
Converts the argument object to the target type.

Implementations are required to either correctly convert the object to the target type, or throw a ConversionFailedException.

The target type may be any reflection type that is possible, but it is usually an instance of Class, or the generic ParameterizedType.

The conversion context can be used to access support data for the conversion. It allows the client to access the classloader, task result resolver, and generic converters if need be.

The caller may or may not do any type checking to ensure that the returned value is actually an instance of the target type. Clients should always ensure and test for their correct implementation.

When implementations of this method delegate conversion of generic elements, they should call ConversionContext.genericChildContext(int) and use the returned conversion context for converting the elements.

conversioncontextThe conversion context.
valueThe object to convert.
targettypeThe target type of the conversion.
The converted object.
ConversionFailedExceptionIf the conversion to the target type fails.