I have a java component in Mule that is returning a String. When I print that string from within the java component, it reads as UTF-8 just fine in the console. However, when I return this as the payload, the subsequent logger and all downstream components can no longer read the UTF-8 characters. I've confirmed that my project's encoding setting is set to 'UTF-8'. I've also:
MULE_ENCODING=UTF-8
before and after the Java component, both as an outbound property and invocation property. message.setEncoding('UTF-8')
with an error stating it could not find the method setEncoding()
Using the following in the java component:
eventContext.getMessage().setPayload(myString);
eventContext.getMessage().setEncoding("UTF-8");
return eventContext.getMessage().getPayload();
Switching to a java transformer instead of a component, using the below config on the transformer, explicitly setting encoding to "UTF-8".
<custom-transformer encoding="UTF-8"
class="myDomain.myJavaTransformer" doc:name="Java"/>
I'm not sure what else to try to ensure the payload coming out of the java component/transformer is not interpreted or converted to another encoding...
The output should read: “Outstanding New Environmental Scientist”
The logger currently outputs is “Outstanding New Environmental Scientistâ€. I've corrected this in other parts of the flow by adding encoding=UTF-8 to any VM endpoints, for example. I've also confirmed that this can print correctly in a logger elsewhere in the flow.
There seems to be something happening after the String is returned from within the java class referenced by the java component and the subsequent mule logger...
try <object-to-string-transformer encoding="..." />
right after your java component