I'm having issues converting a simple JSON message into a Map
Example_1.json:
{"toAddress":"[email protected]",
"fromAddress":"[email protected]",
"subject":"Subject from JSON",
"body":"Body from JSON"}
Spring configuration:
<!-- 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>
Error:
org.springframework.integration.handler.LoggingHandler] - org.springframework.messaging.MessageHandlingException: failed to write Message payload to file; nested exception is java.lang.IllegalArgumentException: unsupported Message payload type [java.util.HashMap], failedMessage=GenericMessage [payload={subject=Subject from JSON, [email protected], body=Body from JSON, [email protected]}, headers={file_originalFile=C:\data\inputDirectory\Example_1.json, id=be65b982-ef47-0207-2ec9-3fdb04837651, file_name=Example_1.json, timestamp=1575407244281}]
Essentially I would like to convert JSON text into a Map, so that I can use expressions such as payload.toAddress to send emails using an outbound-channel-adapter