The
Convert
annotation is used to specify a converter
class to use for serialization. This annotation is used when an
object needs to be serialized but can not be annotated or when the
object can not conform to an existing XML structure. In order to
specify a
Converter
object a field or method can be
annotated like the field below.
@Element
@Convert(ExampleConverter.class)
private Example example;
Note that for the above field the
Element
annotation
is required. If this is used with any other XML annotation such
as the
ElementList
or
Text
annotation
then an exception will be thrown. As well as field and methods
this can be used to suggest a converter for a class. Take the
class below which is annotated.
@Root
@Convert(DemoConverter.class)
public class Demo {
...
}
For the above class the specified converter will be used. This is
useful when the class is used within a
java.util.List
or another similar collection. Finally, in order for this to work
it must be used with the
AnnotationStrategy
which is
used to scan for annotations in order to delegate to converters.