【发布时间】:2023-03-03 19:45:01
【问题描述】:
我在将简单的 JSON 消息转换为地图时遇到问题
Example_1.json:
{"toAddress":"aaa@bbb.com",
"fromAddress":"bbb@ccc.com",
"subject":"Subject from JSON",
"body":"Body from JSON"}
弹簧配置:
<!-- Read file and output to filesIn channel -->
<int:channel id="filesIn" />
<int-file:inbound-channel-adapter id="filesReader"
directory="file:/C:/data/inputDirectory"
filename-pattern="*.json"
channel="filesIn"
prevent-duplicates="true">
<int:poller id="poller" fixed-delay="5000" max-messages-per-poll="1" />
</int-file:inbound-channel-adapter>
<file:file-to-string-transformer input-channel="filesIn" output-channel="strings"/>
<int:json-to-object-transformer input-channel="strings" output-channel="objectsOut" type="java.util.Map"/>
<int:object-to-map-transformer input-channel="objectsOut" output-channel="mapOut"/>
<int-file:outbound-channel-adapter channel="mapOut" directory="file:/C:/data/outputDirectory1" />
<!-- Activate logging -->
<int:channel id="filesIn">
<int:interceptors>
<int:wire-tap channel="LoggingChannel" />
</int:interceptors>
</int:channel>
<int:channel id="strings">
<int:interceptors>
<int:wire-tap channel="LoggingChannel" />
</int:interceptors>
</int:channel>
<int:channel id="objectsOut">
<int:interceptors>
<int:wire-tap channel="LoggingChannel" />
</int:interceptors>
</int:channel>
<int:channel id="mapOut">
<int:interceptors>
<int:wire-tap channel="LoggingChannel" />
</int:interceptors>
</int:channel>
<int:channel id="LoggingChannel" />
<int:service-activator input-channel="LoggingChannel" expression="@LOG.trace('Headers are: {}, Payload is: {} ', headers, payload)" />
<bean id="LOG" class="SafeLoggerFactory" factory-method="getLogger">
<constructor-arg value="integrationEmailLogger"/>
</bean>
错误:
org.springframework.integration.handler.LoggingHandler] - org.springframework.messaging.MessageHandlingException:无法将消息有效负载写入文件;嵌套异常是 java.lang.IllegalArgumentException: 不支持的消息有效负载类型 [java.util.HashMap], failedMessage=GenericMessage [payload={subject=来自 JSON 的主题, fromAddress=bbb@ccc.com, body=来自 JSON 的正文, toAddress= aaa@bbb.com}, headers={file_originalFile=C:\data\inputDirectory\Example_1.json, id=be65b982-ef47-0207-2ec9-3fdb04837651, file_name=Example_1.json, timestamp=1575407244281}]
基本上我想将 JSON 文本转换为 Map,以便我可以使用诸如 payload.toAddress 之类的表达式使用出站通道适配器发送电子邮件
【问题讨论】: