[ 
https://issues.apache.org/jira/browse/CAMEL-27650?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen updated CAMEL-27650:
--------------------------------
    Fix Version/s: 4.25.0
                       (was: 4.24.0)

> camel-once: a number loaded from a resource stays a String, true/false 
> becomes a Boolean
> ----------------------------------------------------------------------------------------
>
>                 Key: CAMEL-27650
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27650
>             Project: Camel
>          Issue Type: Bug
>            Reporter: Claus Ibsen
>            Priority: Minor
>             Fix For: 4.25.0
>
>
> Found while improving the option descriptions of camel-once for CAMEL-23832 
> (commit 
> https://github.com/apache/camel/commit/3c80b51ba543e4de24c73d81ee380bcdc2594ffc).
> These are separate problems of the component; the descriptions commit only 
> documents the current behavior.
> h4. 1. A number loaded from a resource stays a String, while true or false 
> loaded from a resource becomes a Boolean
> {{OnceConsumer.resolveData(Exchange, Object)}} first replaces a value with a 
> resource prefix ({{file:}}, {{classpath:}}, {{http:}}, ...) by the text of 
> that resource. It then checks {{true}}/{{false}} on that resolved text, but 
> tries the Integer and Long conversion on the original option value 
> ({{data}}), not on the resolved text:
> {code:java}
> if ("true".equalsIgnoreCase(answer)) {
>     return true;
> } else if ("false".equalsIgnoreCase(answer)) {
>     return false;
> } else {
>     Object val = camelContext.getTypeConverter().tryConvertTo(Integer.class, 
> exchange, data);
>     ...
>     val = camelContext.getTypeConverter().tryConvertTo(Long.class, exchange, 
> data);
> {code}
> This applies to the body, headers, variables and exchangeProperties options. 
> With {{header.priority=true}} or {{header.priority=classpath:flag.txt}} (file 
> holds {{true}}) the header is a Boolean. With {{header.bar=123}} the header 
> is an Integer, but with {{header.bar=classpath:price.txt}} (file holds 
> {{123}}) it is the String {{123}}.
> Proposed change: convert the resolved text ({{answer}}) to Integer and Long 
> as well, so a value gives the same type whether it is written in the option 
> or loaded from a resource. Or, if resource content should stay text, skip the 
> Boolean conversion for it too. Either way, document the rule.
> _Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to