Announcement Announcement Module
Collapse
No announcement yet.
Spel toJson Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spel toJson

    Hi team,

    I'm currently converting message headers to Strings as shown below:

    Code:
    <beans:bean id="spelSource" class="org.springframework.integration.jdbc.ExpressionEvaluatingSqlParameterSourceFactory">
    	    <beans:property name="parameterExpressions">
    	        <beans:map>
    	            <beans:entry key="UUIDasString"	value ="headers['id'].toString()"/>
    	            <beans:entry key="payload"		value ="payload"/>
    	            <beans:entry key="headers"		value ="headers.toString()"/>
    	        </beans:map>
    	    </beans:property>
    	</beans:bean>
    What I could like to do is something like:
    Code:
    headers.toJSON()
    Is there a simple way to do this?

    Thanks!
    k

  • #2
    You could use a similar technique to the one described here...

    https://github.com/SpringSource/spri...Using-Gateways

    In the chain (downstream of the gateway), you'd use a transformer (expression="headers") and an object-to-json-transformer; you might have trouble converting some of the headers to jSON (replyChannel etc) so you might need to remove them once the headers have been moved to the payload.

    Something like...

    Code:
    <int:header-enricher input-channel="publishingChannel" output-channel="outputConsole">
    	<int:header name="headersAsJson" expression="@headersToJsonFlow.exchange(#root).payload" /> 
    </int:header-enricher>
    
    <int:gateway id="headersToJsonFlow" default-request-channel="foo" />                        
    
    <int:chain input-channel="foo">
    	<int:transformer expression="headers" />
            <!-- some other transformer to remove replyChannel, errorChannel etc might be needed here />
    	<int:object-to-json-transformer />
    </int:chain>
    Then, in your parameter source, use the 'headersAsJson' header.

    Comment

    Working...
    X