【问题标题】:How read a json file with mule?如何用 mule 读取 json 文件?
【发布时间】:2015-05-14 12:38:25
【问题描述】:

我的源代码中有这个部分:

<file:inbound-endpoint connector-ref="fileConnector" path="C:/tmp/input" encoding="UTF-8" mimeType="application/json">
       <file:filename-wildcard-filter pattern="*.json"/>
</file:inbound-endpoint>

<json:json-to-object-transformer returnClass="java.util.HashMap"/>

<logger level="INFO" message="#[message.payload]"/>

一切编译正常!但在执行时抛出下一个异常:“消息:无法从“json”转换为“java.util.HashMap”代码:MULE-ERROR-109”

谁能帮我解决这个错误?

【问题讨论】:

  • 你的 JSON 负载是什么?你想在日志中打印有效载荷还是想从中提取元素值?
  • 我正在调试我的流程,有效载荷的内容是一个字节[]数组。我如何将此数组转换为 json 文件?
  • 我正在放置一个字节数组到对象和对象到 json,现在我有一个我的文件内容字符串,如下所示“参数:\r\n{\r\ n\t\t\t[\r\n\t\t\t\t\t\"key\":\"1\"].......}"。 如何在我的有效载荷中选择“key”的值?
  • 你的 Json 内容是什么?你想在日志中打印什么..整个 Json 或任何特定的 json 值?
  • 这看起来不像是有效的 JSON,这可能是你不能使用 json-to-object-transformer 的原因。

标签: json mule esb


【解决方案1】:

流程如下:

<file:inbound-endpoint 
  connector-ref="fileConnector" path="C:/tmp/input" 
  doc:name="File Input" responseTimeout="10000" 
  encoding="UTF-8" mimeType="text/plain">
  <file:filename-wildcard-filter pattern="*.json"/>
</file:inbound-endpoint>

<json:json-to-object-transformer returnClass="java.util.HashMap"doc:name="JSON to Object"/>`

错误出现在 JSON 文件中。性格 编码不正确,因此我产生了错误 当试图通过<json: json-to-object-transformer returnClass = "java.util.HashMap" doc: name = "JSON to Object" / >进行转换时 使用&lt;file: inbound-endpoint&gt; 读取文件后 我定义为 encoding = "UTF-8"

的属性

解决方案

将JSON文件的字符编码改为“UTF-8”

知识库:

如果异常堆栈是:

消息:无法从“json”转换为“java.util.HashMap”代码: MULE_ERROR-109


异常堆栈是:

  1. 意外字符((代码 65279 / 0xFEFF)“?”):应为有效值(数字、字符串、数组、对象、“真”、“假”或“空”)在 [来源:java.io。 InputStreamReader@2fba237;第 1 行第 2 列 (org.codehaus.jackson.JsonParseException) org.codehaus.jackson.JsonParser: 1433 (null)
  2. 无法从“json”转换为“java.util.HashMap (org.mule.api.transformer.TransformerException) org.mule.module.json.transformers.JsonToObject:132 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)

考虑更改 JSON 文件的字符编码

【讨论】:

    猜你喜欢
    • 2019-11-03
    • 2017-01-02
    • 1970-01-01
    • 2018-10-20
    • 1970-01-01
    • 2012-12-04
    • 2013-04-30
    • 1970-01-01
    • 2017-12-18
    相关资源
    最近更新 更多