Mappings that match on Json Body overwrite each other #631

Closed
opened 2025-12-29 08:31:29 +01:00 by adam · 1 comment
Owner

Originally created by @asos-alexhaigh on GitHub (Sep 16, 2024).

Originally assigned to: @StefH on GitHub.

Describe the bug

Using WireMock .Net TestContainers

When adding multiple mappings using WithBody WireMock does not seem to distinguish between the serialized content overwriting the previous mapping.

These have the same path, but a different JSON body in the request.

For example I have a different "firstName" in my JSON object, but the second mapping overwrites the first so I get a "Mapping not found" error when both mappings are set up.

Expected behavior:

When a serialized object has different properties I would expect WireMock to be able to tell the difference between them so that different responses could be returned.

Test to reproduce

  • 1 Use Gist below to post mappings to client
  • 2 Make post request by serializing object created in UserEndpointData class

Gist with setup

Originally created by @asos-alexhaigh on GitHub (Sep 16, 2024). Originally assigned to: @StefH on GitHub. ### Describe the bug Using WireMock .Net TestContainers When adding multiple mappings using `WithBody` WireMock does not seem to distinguish between the serialized content overwriting the previous mapping. These have the same path, but a different JSON body in the request. For example I have a different "firstName" in my JSON object, but the second mapping overwrites the first so I get a "Mapping not found" error when both mappings are set up. ### Expected behavior: When a serialized object has different properties I would expect WireMock to be able to tell the difference between them so that different responses could be returned. ### Test to reproduce - 1 Use Gist below to post mappings to client - 2 Make post request by serializing object created in `UserEndpointData` class ### Other related info [Gist with setup](https://gist.github.com/asos-alexhaigh/c9945680e001628f088929efbdc903f4)
adam added the question label 2025-12-29 08:31:29 +01:00
adam closed this issue 2025-12-29 08:31:29 +01:00
Author
Owner

@StefH commented on GitHub (Sep 18, 2024):

@asos-alexhaigh
I think the issue here is that both mappings are using the same GUID (66cb85f5-6a2c-4f67-b685-3fcb9275e17a). If you want different mappings, use a unique GUID, or do not provide the GUID.

@StefH commented on GitHub (Sep 18, 2024): @asos-alexhaigh I think the issue here is that both mappings are using the same GUID (66cb85f5-6a2c-4f67-b685-3fcb9275e17a). If you want different mappings, use a unique GUID, or do not provide the GUID.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#631