spring-cloud-contract-samples icon indicating copy to clipboard operation
spring-cloud-contract-samples copied to clipboard

Confusing behaviour of serialization/deserialization of message in consumer_rabbit_middleware module

Open mkrzywanski opened this issue 3 years ago • 1 comments

Describe the bug I am not sure if this is a bug but it concerns consumer_rabbit_middleware module. The message that is produced by StubTrigger is serialized twice. Therfore it results in escaped json string that is consumed by listener. In the end we end up with instance of Foo2 that has field foo with value of json ({"foo":"example"}).

image

The actual body is first created in StubRunnerExecutor::send method (JsonOutput.toJson method call). Then the resulting json string is serialized again : here when writing the payload to bytes - we end up with escaped json. The deserialization works since Foo2 has constructor that accepts String.

The solution would be to convert generic payload to bytes without using ObjectMapper (it will be String in this case so simple cast could be sufficient).

If it is not desired behaviour (at least I suspect so) I could create a PR for this.

mkrzywanski avatar Aug 01 '21 17:08 mkrzywanski

I don't think this is intended. Please feel free to file a PR against contract 3.0.x branch.

marcingrzejszczak avatar Aug 09 '21 08:08 marcingrzejszczak