mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
[PR #1301] [MERGED] Fix errors when converting response bodies with top-level JSON arrays to C# code #1326
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/wiremock/WireMock.Net/pull/1301
Author: @asaf92
Created: 5/21/2025
Status: ✅ Merged
Merged: 5/22/2025
Merged by: @StefH
Base:
master← Head:fix/json-array-parsing📝 Commits (1)
ae6a76ffix errors when converting json arrays to C# code📊 Changes
1 file changed (+2 additions, -2 deletions)
View changed files
📝
src/WireMock.Net/Util/CSharpFormatter.cs(+2 -2)📄 Description
When trying to convert static mapping to C# code, I ran into an exception when the body is a top-level array rather than a pure string or a (non-array) JSON object.
The problem is that this code doesn't distinguish between arrays and objects, and assumes that every non-null that isn't a string is an object:
My solution is to load a JToken instead of a JObject in ConvertToAnonymousObjectDefinition, which seems like the original intention given that ConvertJsonToAnonymousObjectDefinition (which is defined in an internal class) expects a JToken and isn't called anywhere else in the code.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.