INT-3556: Payload Conversion Documentation

JIRA: https://jira.spring.io/browse/INT-3556

Clarify when a `GenericConverter` might be needed rather
than a simple `Converter`.
This commit is contained in:
Gary Russell
2014-11-07 12:57:53 -05:00
committed by Artem Bilan
parent 96d18d43a7
commit 1018fcf361
2 changed files with 85 additions and 2 deletions

View File

@@ -593,8 +593,21 @@ any transaction configuration essentially allowing you to enhance the behavior o
To register a Converter all you need is to implement
<interfacename>org.springframework.core.convert.converter.Converter</interfacename>,
<interfacename>org.springframework.core.convert.converter.GenericConverter</interfacename> or
<interfacename>org.springframework.core.convert.converter.ConverterFactory</interfacename> and define it via
convenient namespace support:
<interfacename>org.springframework.core.convert.converter.ConverterFactory</interfacename>.
</para>
<para>
The <classname>Converter</classname> implementation is the simplest and converts
from a single type to another. For more sophistication, such as converting to a class hierarchy, you would
implement a <classname>GenericConverter</classname> and possibly a <classname>ConditionalConverter</classname>.
These give you complete access to the <emphasis>from</emphasis> and <emphasis>to</emphasis> type descriptors
enabling complex conversions. For example, if you have an abstract class <classname>Foo</classname> that is
the target of your conversion (parameter type, channel data type etc) and you have two concrete implementations
<classname>Bar</classname> and <classname>Baz</classname> and you wish to convert to one or the other based
on the input type, the <classname>GenericConverter</classname> would be a good fit. Refer to the JavaDocs for
these interfaces for more information.
</para>
<para>
When you have implemented your converter, you can register it with convenient namespace support:
<programlisting language="xml"><![CDATA[<int:converter ref="sampleConverter"/>
<bean id="sampleConverter" class="foo.bar.TestConverter"/>]]></programlisting>