1
votes

I'm using Spring Cloud Edgware. SR3 and Spring Cloud Stream 2.0.1 Release.

I have created testprocessor app using spring cloud stream 2.0. Created the sample stream:

stream create TEST1 --definition "http --server.port=8888 | testprocessor | uploader --spring.cloud.stream.bindings.input.contentType='text/plain1' "

Deployed in Spring cloud local server.

//testprocessor apps method signature is
@StreamListener(Processor.INPUT)
@sendto(Processor.OUTPUT)
public String transform(Object payload) {

}

In application.properties of this app, i have configured below properties spring.cloud.stream.bindings.input.content-type=application/json;

Sample input data:

http post --contentType 'application/json' --data '{\"isbn\": \"1599869772", "title": "The Art of War", "author": "Sun Tzu"}' --target http://localhost:8888

When i post above sample data, i am always getting Object payload is byte[] object like [B@5b2ff6e7 but not getting actual JSON String. Please can you help on this issue?

Note: If i build same testprocessor app using spring cloud stream 1.3.1 version. It is working fine. I am getting JSON string. Why it is not working using spring cloud stream 2.0.1

1

1 Answers

1
votes

The transformer application has an expression option, so you can do like this:

--expression='new String(payload)'

And you'll get a JSON string there in the public String transform(Object payload) method.

The related GH issue: https://github.com/spring-cloud-stream-app-starters/transform/issues/6