Skip to content

Conversation

@squakez
Copy link
Contributor

@squakez squakez commented Jan 27, 2026

Closes CAMEL-22910

This one could be a good helper for final users to spare time on casting and using raw types. The new utility methods allow the user passing from the following:

        @SuppressWarnings("unchecked")
        List<String> values =
            myExchange.getProperty("myProp", List.class);

to:

        List<String> values = myExchange.getPropertyAsList("myProp", String.class);

There are also utilities for Map, Collections, Set and Optional on getProperty and getVariable.

Description

Target

  • I checked that the commit is targeting the correct branch (Camel 4 uses the main branch)

Tracking

  • If this is a large change, bug fix, or code improvement, I checked there is a JIRA issue filed for the change (usually before you start working on it).

Apache Camel coding standards and style

  • I checked that each commit in the pull request has a meaningful subject line and body.
  • I have run mvn clean install -DskipTests locally from root folder and I have committed all auto-generated changes.

List<T> result = new ArrayList<>();
for (Object element : iterable) {
if (!elementType.isInstance(element)) {
return null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we return null, skip the item or throw the exception? I had followed the original API, for which any error on the cast of the property would return null. But maybe we can change it in these implementations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about skipping and LOG.warn the skipped element?

}

if (!valueType.isInstance(rawValue)) {
return null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question about the casting posed above.

@github-actions
Copy link
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟

🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run

  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot.

  • You can label PRs using build-all, build-dependents, skip-tests and test-dependents to fine-tune the checks executed by this PR.

  • Build and test logs are available in the Summary page. Only Apache Camel committers have access to the summary.

  • ⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@davsclaus
Copy link
Contributor

Beware the Exchange API is already big and its a central API for Camel end users.

End users should use variables and not exchange properties. The latter is more for Camel internally and component developers and old school before variables was added to Camel.

We have ExchangeHelper where extra methods is better suited that are not commonly in use, or would rarely need to be.

So if you have some internal API cleanup where you want to remove those suppress warning then IMHO its not new methods on Exchange we should add, but on ExchangeHelper and then use that internally in Camel.


List<T> result = new ArrayList<>();
for (Object element : iterable) {
if (!elementType.isInstance(element)) {
Copy link
Contributor

@orpiske orpiske Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that this isIstance check within a loop is very likely to hit the JVM secondary super issue which triggers a false sharing problem and affects pretty much everything older than Java 22.

@squakez
Copy link
Contributor Author

squakez commented Jan 28, 2026

Thanks for the reviews, the goal of this PR is more kind of experimental to provide some simplification to both final users and internal development as well. More than just skipping the warnings it is an attempt to bring some easier API for the final user. I will move them into the ExchangeHelper. I was also thinking to do some similar upper layer API for making it simpler to extract the body. I'll keep it as a draft while I continue refining these possibilities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants