如何在Mule 4中将ManagedCursorStreamProvider转换为JSOn对象 [英] How to convert ManagedCursorStreamProvider to JSOn object in mule 4

查看:171
本文介绍了如何在Mule 4中将ManagedCursorStreamProvider转换为JSOn对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Manage子中将ManagedCursorStreamProvider转换为Json对象. 我编写了一个Java方法,将Json对象作为输入

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"}

调用静态

arg0 : payload

使用invoke static调用的Java函数

Java Function called using invoke static

public static func(JsonObject json){
}

我遇到以下错误:

期望的参数是[com.google.gson.JsonObject jsonObject]和 尝试使用参数进行调用 [org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider arg0]. 找不到合适的转换来匹配预期的类型 参数[jsonObject].

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].

更新: 我已经更新了我的java方法,以接受String作为输入.

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".

推荐答案

Mule不知道如何转换为GSON JsonObject.您可以使用DataWeave将其转换为Java映射.或者,您可以将Java方法的参数更改为String,而Mule将透明地将流转换为String.确保使用最新版本的Java模块.

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.

如果要转换为自定义类型的对象,则需要自己用Java实现.

If you want to convert to a custom type of object you will need to implement it yourself in Java.

这篇关于如何在Mule 4中将ManagedCursorStreamProvider转换为JSOn对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆