Spring integration 问题:将.json文件转换为映射
我在将简单的JSON消息转换为映射时遇到问题 示例_1.json:Spring integration 问题:将.json文件转换为映射,spring-integration,Spring Integration,我在将简单的JSON消息转换为映射时遇到问题 示例_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" /> <in
{"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=subject from JSON,fromAddress]=bbb@ccc.com,body=JSON中的body,toAddress=aaa@bbb.com},标题={file_originalFile=C:\data\inputDirectory\Example_1.json,id=be65b982-ef47-0207-2ec9-3fdb04837651,file_name=Example_1.json,timestamp=1575407244281}]
基本上,我希望将JSON文本转换为映射,以便使用payload.toAddress等表达式使用出站通道适配器发送电子邮件。您应该始终包含完整的堆栈跟踪;截断的堆栈跟踪是无用的 为什么有一个
对象映射转换器
?json到对象转换器
已经为您创建了一个映射;o-t-m-t是多余的
文件
int file:outbound channel adapter
不知道如何处理映射有效负载。这就是失败的地方。Hi Gary-感谢指针!我删除了文件到字符串和对象到映射转换器以及文件出站通道适配器。然后,我能够使用有效负载中的信息来丰富标头