From c31abf8f3fbd1961244bff19de62367bc3531792 Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Tue, 10 Sep 2013 11:30:43 -0300 Subject: [PATCH] Added Converter Resolution explanation --- convert/README.asciidoc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/convert/README.asciidoc b/convert/README.asciidoc index 80e083776f..cba6312913 100644 --- a/convert/README.asciidoc +++ b/convert/README.asciidoc @@ -64,8 +64,17 @@ Additionally, you may directly inject typed converters: @Inject Converter converter; ---- ==== +Converter Resolution:: +By default, the Converter API will automatically attempt to find the assigned converter by doing the following checks: -Custom converters:: +- Check if a custom converter was registered (see next section); +* If no custom converter is found, the following checks are made: +** Given a source type and a target type, check if the target type has a constructor with only the source type as a parameter. eg: public static MyClass valueOf(String str){...} +** Given a source type and a target type check if the target type has a static method valueOf receiving the source type as a parameter. eg: public static MyClass valueOf(String str){...} +- If converter resolution fails, a ConverterNotFoundException is thrown. + +==== +Custom converters:: The convert API can be extended to register converters for types that are not supported by default. This is a two step process involving creation of a new type that extends from `Converter`, and of a `ConverterGenerator`. These custom converters will be made automatically available to other addons that depend on the convert addon.