Hi All,

I have a custom type converter to a custom data model.

For my purposes, some input types need to be converted to null and  the
exchange need to be processed to add an header even if conversion results
in null.

For example (simplified):

@Converter
public static MyPayload convert(MessageContentsList message, Exchange
exchange) {
  if (exchange != null) {
    exchange.getIn().getHeaders().put("newHeaderName",
"someNewHeaderValue");
  }
  return null;
}

Well, the first time the converter is invoked it works (the exchange has
the new header),
The second time invokation of "convert" get skipped in
BaseTypeConverterRegistry.doConvertTo(...) as the following if statement
resolves to true:

        // check if we have tried it before and if its a miss
        TypeMapping key = new TypeMapping(type, value.getClass());
        if (misses.containsKey(key)) {
            // we have tried before but we cannot convert this one
            return Void.TYPE;
        }

I've seen that there have been "semantical ambiguity of null"  in the past,
which should have been solved in issue CAMEL-84, but I've not understood it
and how I should handle this scenario in a proper way.

I guess I'm using type converter in a bad style, but as I don't understand
why I can't guess the good way.

The only idea I have is to create a class MyEmptyPayload implements
MyPayload { } and return an instance to this instead of null, but I still
would like to understand the reasons.

Could someone orient me toward the right solution?

Thank you very much,
Cristiano

Reply via email to