Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B6535200BD4 for ; Thu, 1 Dec 2016 15:14:01 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B4ECC160B10; Thu, 1 Dec 2016 14:14:01 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D40F6160B0B for ; Thu, 1 Dec 2016 15:14:00 +0100 (CET) Received: (qmail 32886 invoked by uid 500); 1 Dec 2016 14:14:00 -0000 Mailing-List: contact issues-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list issues@camel.apache.org Received: (qmail 32877 invoked by uid 99); 1 Dec 2016 14:14:00 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Dec 2016 14:14:00 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id E15722C1F54 for ; Thu, 1 Dec 2016 14:13:59 +0000 (UTC) Date: Thu, 1 Dec 2016 14:13:59 +0000 (UTC) From: "Luca Burgazzoli (JIRA)" To: issues@camel.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (CAMEL-10548) Converter from List to String is not found when @EnableAutoConfiguration is used MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 01 Dec 2016 14:14:01 -0000 [ https://issues.apache.org/jira/browse/CAMEL-10548?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15712058#comment-15712058 ] Luca Burgazzoli edited comment on CAMEL-10548 at 12/1/16 2:13 PM: ------------------------------------------------------------------ Yes an not :-) Spring says that it can convert from List to String and it is true but then thing is that Spring can't convert from Person to String as FallbackObjectToStringConverter can convert POJO if they have a String constructor or they have a valueOf(String) method (yeah, even if we are convertinf the opposite way). What spring does under the hoods is looping over the collection and search a converter for the each element which of course may not be present. I'm going to submit an issue to Spring but in the meantime I have this hack: https://github.com/lburgazzoli/apache-camel/commit/daf9c98f5d344d62cf551084dd4edb99e6509c52 Would it be acceptable ? was (Author: lb): Yes an not :-) Spring says that it can convert from List to String and it is true but then thing is that Spring can't convert from Person to String as FallbackObjectToStringConverter can convert POJO if they have a String constructor or they have a valueOf(String) method. What spring does under the hoods is looping over the collection and search a converter for the each element which of course may not be present. I'm going to submit an issue to Spring but in the meantime I have this hack: https://github.com/lburgazzoli/apache-camel/commit/daf9c98f5d344d62cf551084dd4edb99e6509c52 Would it be acceptable ? > Converter from List to String is not found when @EnableAutoConfiguration is used > -------------------------------------------------------------------------------- > > Key: CAMEL-10548 > URL: https://issues.apache.org/jira/browse/CAMEL-10548 > Project: Camel > Issue Type: Bug > Components: camel-spring-boot > Reporter: Luca Burgazzoli > Assignee: Luca Burgazzoli > Fix For: 2.19.0 > > > This very simple spring-boot application : > {code:java} > @SpringBootApplication > public class Application { > public static void main(String[] args) { > SpringApplication.run(Application.class, args); > } > @Component > public class MyRouteBuilder extends RouteBuilder { > @Override > public void configure() throws Exception { > from("timer:person") > .setBody().constant(Arrays.asList( > new Person("Peter", 25), > new Person("John", 33) > )) > .log("Body is ${body}"); > } > } > public static class Person { > private String name; > private int age; > public Person(String name, int age) { > this.name = name; > this.age = age; > } > public String getName() { > return name; > } > public void setName(String name) { > this.name = name; > } > public int getAge() { > return age; > } > public void setAge(int age) { > this.age = age; > } > @Override > public String toString() { > return "Person{" + > "name='" + name + '\'' + > ", age=" + age + > '}'; > } > } > } > {code} > Fails to resolve the simple expression ${body} because of the following exception: > {code} > org.apache.camel.TypeConversionException: Error during type conversion from type: java.lang.String to the required type: java.lang.String with value [Person{name='Peter', age=25}, Person{name='John', age=33}] due Failed to convert from type [java.util.Arrays$ArrayList] to type [java.lang.String] for value '[Person{name='Peter', age=25}, Person{name='John', age=33}]'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.Arrays$ArrayList] to type [java.lang.String] > at org.apache.camel.impl.converter.BaseTypeConverterRegistry.createTypeConversionException(BaseTypeConverterRegistry.java:629) ~[camel-core-2.18.0.jar:2.18.0] > at org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseTypeConverterRegistry.java:150) ~[camel-core-2.18.0.jar:2.18.0] > at org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:41) ~[camel-core-2.18.0.jar:2.18.0] > at org.apache.camel.builder.ExpressionBuilder$75.evaluate(ExpressionBuilder.java:1795) ~[camel-core-2.18.0.jar:2.18.0] > at org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:36) ~[camel-core-2.18.0.jar:2.18.0] > at org.apache.camel.processor.LogProcessor.process(LogProcessor.java:53) ~[camel-core-2.18.0.jar:2.18.0] > at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) ~[camel-core-2.18.0.jar:2.18.0] > at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542) ~[camel-core-2.18.0.jar:2.18.0] > at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197) [camel-core-2.18.0.jar:2.18.0] > at org.apache.camel.processor.Pipeline.process(Pipeline.java:120) ~[camel-core-2.18.0.jar:2.18.0] > at org.apache.camel.processor.Pipeline.process(Pipeline.java:83) ~[camel-core-2.18.0.jar:2.18.0] > at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197) [camel-core-2.18.0.jar:2.18.0] > at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:192) [camel-core-2.18.0.jar:2.18.0] > at org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:76) [camel-core-2.18.0.jar:2.18.0] > at java.util.TimerThread.mainLoop(Timer.java:555) [na:1.8.0_112] > at java.util.TimerThread.run(Timer.java:505) [na:1.8.0_112] > Caused by: org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.util.Arrays$ArrayList] to type [java.lang.String] for value '[Person{name='Peter', age=25}, Person{name='John', age=33}]'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.Arrays$ArrayList] to type [java.lang.String] > at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:42) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE] > at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:192) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE] > at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:176) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE] > at org.apache.camel.spring.boot.SpringTypeConverter.convertTo(SpringTypeConverter.java:46) ~[camel-spring-boot-2.18.0.jar:2.18.0] > at org.apache.camel.impl.converter.BaseTypeConverterRegistry.doConvertTo(BaseTypeConverterRegistry.java:346) ~[camel-core-2.18.0.jar:2.18.0] > at org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseTypeConverterRegistry.java:133) ~[camel-core-2.18.0.jar:2.18.0] > ... 14 common frames omitted > Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.Arrays$ArrayList] to type [java.lang.String] > at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:313) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE] > at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:195) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE] > at org.springframework.core.convert.support.CollectionToStringConverter.convert(CollectionToStringConverter.java:68) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE] > at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:36) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE] > ... 19 common frames omitted > {code} > The root cause is spring failing to find a converter for Person --> String and as the SpringTypeConverter registered by camel-spring-boot is one of the fallback converters used by BaseTypeConverterRegistry, it leads Camel to fail too. > As today is a Camel TypeConverter fails with an exception while looping over fallback converters, the loops ends and the conversion fails too. It may turn out that the bug is caused by the way camel uses Spring's type converters but it may be good to catch exceptions and try the next converter, [~davsclaus] make sense ? > A workaround is to create a custom converter for the class: > {code:java} > @Component > public class PersonConverter implements Converter { > @Override > public String convert(Person source) { > return source.toString(); > } > } > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)