gpt4 book ai didi

mule - 一步将 ByteArray 转换为 java.lang.Object

转载 作者:行者123 更新时间:2023-12-01 18:56:33 24 4
gpt4 key购买 nike

enter image description here如果 ByteArrayToObject 返回 String,它的用途是什么?

在我的流程中,我正在使用 mule 请求器从文件中读取 Json 内容,通过执行以下 3 个步骤在数据编织之前转换为 java.lang.Object (1) 字节数组转字符串 (2) 对象转JSON (3) JSONTOObject

我想使用 ByteArrayToObject 转换器将上述 3 个步骤合并为一个,但根据文档,ByteArrayToObject 返回 String

https://docs.mulesoft.com/mule-user-guide/v/3.6/using-transformers

有没有办法将 3 个步骤合并为 1 个步骤?

最佳答案

您无法将有效负载转换为 java.lang.Object,因为它已经是 java.lang.Object 的实例。在Java中,所有对象都继承Object :类对象是类层次结构的根。每个类都有 Object 作为父类(super class)

如果您正在从文件中读取 JSON 内容,并且想要将内容转换为某个类实例,例如 com.mycompany.Apple,您可以直接使用 JSONToObject Transformer,指定 >returnClass 参数

<json:json-to-object-transformer returnClass="com.mycompany.Apple" doc:name="JSON to Apple"/>

您可能想看看 native Json support documentation

根据文档,ByteArrayToObject 可以以两种方式使用:

  • 如果字节数组是序列化的 Java 对象,那么您可以使用 returnClass 参数将其反序列化为该对象。
  • 如果不是序列化的Object,那么它将被转换为String

关于mule - 一步将 ByteArray 转换为 java.lang.Object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40664108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com