groovyspring-xd

How we can add a field to JSON stream in spring XD?


How I can add a timestamp field if it doesn't exist in JSON stream in spring xd, I think we can use a using groovy script for that.

Suppose my JSON stream is {node : value} I want to add one more field timestamp if it does't exist {node : value, timestamp : 23432434}

stream create example --definition "http | transform --script='file:addTime.groovy'" --deploy

Thanks.


Solution

  • In your script, use a JsonToObjectTransformer to transform to a LinkedHashMap; then put the new map entry if absent, then an ObjectToJsonTransformer.