I am using Spring boot 1.2.2.Release and Java 8, the problem is that Spring is wrapping Optional payload
into new Optional objects as many times as I am passing it through transformer/service activator
. E.g.
@ServiceActivator(inputChannel = ..., outputChannel = ...)
public Optional<Foo> transform() {returns -> Optional.of(foo);}
@ServiceActivator(inputChannel = ..., outputChannel = ...)
public Optional<Foo> doSomething1(Opional<Foo> payload) {
payload.ifPresent(f -> {System.out.println(f.getId());}); // this line throws ClassCastException
return foo;
}
The reason why above code throws ClassCastExcpetion(cannot cast java.util.Optional to Foo) because payload
instead of containing foo
as value contains another Optional Object and that Optional object contains foo
as value.
I have read this where it mentioned
Now Spring Integration consistently handles the Java 8's Optional type.
I even tried with exact version of the framework mentioned in the document but no success
Aucun commentaire:
Enregistrer un commentaire