问题
How to convert ManagedCursorStreamProvider to Json object in mule. I have written a java method which takes the Json Object as input
Request Payload:
{ a: "one",
b : "two"}
Invoke static
arg0 : payload
Java Function called using invoke static
public static func(JsonObject json){
}
I am getting the following error:
Expected arguments are [com.google.gson.JsonObject jsonObject] and invocation was attempted with arguments [org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider arg0]. No suitable transformation was found to match the expected type for the parameter [jsonObject].
UPDATE: I have updated my java method to accept String as input.
"Cannot coerce Object { encoding: UTF-8, mediaType: application/json; charset=UTF-8, mimeType: application/json, raw: org.mule.weave.v2.el.SeekableCursorStream@868075a } (org.mule.weave.v2.el.MuleTypedValue@7c0c5e89) to String
1| arg0 : vars.req as String
^^^^^^^^^^^^^^^^^^
Trace:
at main (line: 1, column: 8)" evaluating expression: "arg0 : vars.req as String".
回答1:
Mule doesn't know how to convert to a GSON JsonObject. You can use DataWeave to transform it into a Java map. Alternatively, you can change the argument of the Java method to String and Mule will transparently convert the stream to a String. Be sure to use the latest version of the Java module.
If you want to convert to a custom type of object you will need to implement it yourself in Java.
来源:https://stackoverflow.com/questions/61095074/how-to-convert-managedcursorstreamprovider-to-json-object-in-mule-4