public interface GenericConverter
これは、Converter SPI インターフェースの中で最も柔軟性がありますが、最も複雑でもあります。GenericConverter は、複数のソース / ターゲット型ペア間の変換をサポートできるという点で柔軟性があります(getConvertibleTypes()
を参照してください。さらに、GenericConverter 実装は、型変換プロセス中にソース / ターゲット field context
にアクセスできます。これにより、ソースおよびターゲットフィールドのメタデータを解決できます。変換ロジックに影響を与えるために使用できるアノテーションとジェネリクス情報。
このインターフェースは、より単純な Converter
または ConverterFactory
インターフェースで十分な場合は、通常使用しないでください。
実装では、ConditionalConverter
を追加で実装できます。
TypeDescriptor
, Converter
, ConverterFactory
, ConditionalConverter
修飾子と型 | インターフェースと説明 |
---|---|
static class | GenericConverter.ConvertiblePair ソースとターゲットのクラスペアのホルダー。 |
修飾子と型 | メソッドと説明 |
---|---|
ObjectSE | convert(ObjectSE source, TypeDescriptor sourceType, TypeDescriptor targetType) ソースオブジェクトを TypeDescriptor で記述された targetType に変換します。 |
SetSE<GenericConverter.ConvertiblePair> | getConvertibleTypes() このコンバーターが変換できるソースとターゲットの型を返します。 |
@Nullable SetSE<GenericConverter.ConvertiblePair> getConvertibleTypes()
各エントリは、ソースからターゲットへの変換可能な型のペアです。
conditional converters
の場合、このメソッドは null
を返し、ソースとターゲットのすべてのペアを考慮する必要があることを示します。
@Nullable ObjectSE convert(@Nullable ObjectSE source, TypeDescriptor sourceType, TypeDescriptor targetType)
TypeDescriptor
で記述された targetType に変換します。source
- 変換するソースオブジェクト (null
の場合があります)sourceType
- 変換元のフィールドの型記述子 targetType
- 変換先のフィールドの型記述子