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

46 views Asked by At

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.

1

There are 1 answers

1
Gary Russell On BEST ANSWER

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