I’m trying to follow the transformer example in the documentation that converts a string input into a list of URLs, but it’s throwing an error.
The example is here: http://www.mulesoft.org/documentation/display/MULE3USER/Transformer+Annotation#TransformerAnnotation-WorkingwithCollections
My code for the transformer is copy-pasted from theirs.
When I first did it, I set the transformer by putting in my config xml:
<custom-transformer class="com.test.transformer.StringToListTransformer" doc:name="StringToUrlList"/>
Noting the requirement to ‘register’ the transformer, I later added in the beginning of the file (after the opening tag):
<spring:bean id="stringToListTransformer" class="com.test.transformer.StringToListTransformer"/>
However, when I run the app, I get the following error:
Exception in thread "main" org.mule.module.launcher.DeploymentInitException: IllegalStateException: Cannot convert value of type [com.test.transformer.StringToListTransformer] to required type [org.mule.api.processor.MessageProcessor] for property 'messageProcessors[3]': no matching editors or conversion strategy found
You can’t use a class annotated with
@Transformeras acustom-transformerbecause it is not a realorg.mule.api.processor.MessageProcessor. Only real message processors can be used directly in the XML configuration and invoked explicitly.As the doc for
@Transformersays:If you want to have your transformer kick-in in a flow, you’ll need to use:
assuming it returns a list and there are no other suitable registered transformers with a higher priority.
Otherwise, create a real transformer by extending
org.mule.transformer.AbstractMessageTransformerand then use it withcustom-transformer.