spring-cloud-contract-samples
spring-cloud-contract-samples copied to clipboard
Confusing behaviour of serialization/deserialization of message in consumer_rabbit_middleware module
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"}).

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.
I don't think this is intended. Please feel free to file a PR against contract 3.0.x branch.