Reputation: 531
In the example below, When I create variable in Transform, I sometimes use application/java and some times use application/json . It seems that the target system using this variable doesn't care whether the output is JSON or Java. Only in a few cases does it matter. My gut feeling is that the Mule platform will automatically convert it to the proper type, even if you set it incorrectly.
My question is: In which situations should I use output application/java or output application/json? Is there a general rule to follow?
Any suggestion or ideas are more than weclome!
%dw 2.0
output application/java
---
{
companyCode: attributes.queryParams.companyCode,
((updSince: attributes.queryParams.updSince)) if(!isEmpty(attributes.queryParams.updSince)),
((updBefore: attributes.queryParams.updBefore)) if(!isEmpty(attributes.queryParams.updBefore)),
((updDate: attributes.queryParams.updDate)) if(!isEmpty(attributes.queryParams.updDate)),
limit: attributes.queryParams.limit as Number default 200,
page: attributes.queryParams.page as Number default 1
}
Upvotes: 0
Views: 45
Reputation: 25812
The question doesn't provide details on how are you using that output so I can only give general advise.
In general if you are using the output of a transformation to perform further transformations or processing inside a Mule application it is better to output to Java (application/java
). That is because Java is the "native" representation in Mule. It doesn't requires processing effort in parsing/formatting like any other format. It can be expensive in resources, like CPU and memory, to convert between formats so it only should be done only when really needed. Otherwise you may find issues when the application is under load.
On the other hand if you are sending that value outside the application, for example using an HTTP connector, and it should be received as JSON then it is Ok to output to JSON, XML or whatever format the receiving party is expecting. Note that connectors may be able to transform the value automatically between input and expected formats, but if you want to be sure you can make the transformation explicitly.
Upvotes: 1