finalResult = handleReturnAnnotation(returnExpression, result, invocationContext);
DataType finalType = DataTypeFactory.createFromObject(finalResult);
if (!requiredType.isCompatibleWith(finalType))
{
Transformer transformer = muleContext.getRegistry().lookupTransformer( finalType, requiredType);
finalResult = transformer.transform(finalResult);
}
}
else
{
if (requiredType.getType().equals(MuleMessage.class))
{
finalResult = result.getMessage();
}
else if (requiredType.getType().equals(Response.class))
{
finalResult = result;
}
else
{
DataType sourceType = DataTypeFactory.createFromObject(result.getMessage());
if(requiredType.isCompatibleWith(sourceType))
{
finalResult = result.getPayload();
}
else
{
Transformer transformer = muleContext.getRegistry().lookupTransformer(sourceType, requiredType);
finalResult = transformer.transform(result.getPayload());
}
}
}