GetAdminMappingsResult in WireMock.Org.Abstractions should contain list of mappings #554

Closed
opened 2025-12-29 08:30:03 +01:00 by adam · 8 comments
Owner

Originally created by @roengstrom on GitHub (Nov 23, 2023).

Originally assigned to: @StefH on GitHub.

Describe the bug

When running a dedicated instance of Wiremock in a docker container I cannot fetch the configured mappings. It seems like GetAdminMappingsResult expects an instance of Mappings but according to the Wiremock API documentation, this should not be an object but an array. So when I call the method I get an exception:

   Newtonsoft.Json.JsonSerializationException : Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'WireMock.Org.Abstractions.Mappings' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path 'mappings', line 2, position 16.
  Stack Trace:
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureArrayContract(JsonReader reader, Type objectType, JsonContract contract)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at RestEase.JsonResponseDeserializer.Deserialize[T](String content, HttpResponseMessage response, ResponseDeserializerInfo info)
   at RestEase.Implementation.Requester.Deserialize[T](String content, HttpResponseMessage response, IRequestInfo requestInfo)
   at RestEase.Implementation.Requester.RequestAsync[T](IRequestInfo requestInfo)

Expected behavior:

I expect to not get an exception and instead get an instance of GetAdminMappingsResult containing a list of mappings.

Test to reproduce

  • 1 Start docker container running Wiremock
docker run -it --rm -p 8080:8080 wiremock/wiremock:3.0.0-1-alpine
  • 2 Fetch the mappings using the client
var wireMockBaseUrl = "http://localhost:8080";
var client = RestClient.For<IWireMockOrgApi>(wireMockBaseUrl);
await client.GetAdminMappingsAsync(null, null);
Originally created by @roengstrom on GitHub (Nov 23, 2023). Originally assigned to: @StefH on GitHub. ### Describe the bug When running a dedicated instance of Wiremock in a docker container I cannot fetch the configured mappings. It seems like `GetAdminMappingsResult` expects an instance of `Mappings` but according to the [Wiremock API documentation](https://wiremock.org/docs/standalone/admin-api-reference/), this should not be an object but an array. So when I call the method I get an exception: ``` Newtonsoft.Json.JsonSerializationException : Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'WireMock.Org.Abstractions.Mappings' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array. Path 'mappings', line 2, position 16. Stack Trace: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureArrayContract(JsonReader reader, Type objectType, JsonContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at RestEase.JsonResponseDeserializer.Deserialize[T](String content, HttpResponseMessage response, ResponseDeserializerInfo info) at RestEase.Implementation.Requester.Deserialize[T](String content, HttpResponseMessage response, IRequestInfo requestInfo) at RestEase.Implementation.Requester.RequestAsync[T](IRequestInfo requestInfo) ``` ### Expected behavior: I expect to not get an exception and instead get an instance of `GetAdminMappingsResult` containing a list of mappings. ### Test to reproduce - 1 Start docker container running Wiremock ``` docker run -it --rm -p 8080:8080 wiremock/wiremock:3.0.0-1-alpine ``` - 2 Fetch the mappings using the client ``` var wireMockBaseUrl = "http://localhost:8080"; var client = RestClient.For<IWireMockOrgApi>(wireMockBaseUrl); await client.GetAdminMappingsAsync(null, null); ```
adam added the bug label 2025-12-29 08:30:03 +01:00
adam closed this issue 2025-12-29 08:30:03 +01:00
Author
Owner

@StefH commented on GitHub (Nov 28, 2023):

https://github.com/WireMock-Net/WireMock.Net/pull/1023

@StefH commented on GitHub (Nov 28, 2023): https://github.com/WireMock-Net/WireMock.Net/pull/1023
Author
Owner

@StefH commented on GitHub (Nov 28, 2023):

@roengstrom
Please note that this API is not 100% guaranteed to be compatible with the WireMock.Org version, however I did change the code, can you please test preview 1.5.40-ci-17965 ?

https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

@StefH commented on GitHub (Nov 28, 2023): @roengstrom Please note that this API is not 100% guaranteed to be compatible with the WireMock.Org version, however I did change the code, can you please test preview `1.5.40-ci-17965` ? https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
Author
Owner

@roengstrom commented on GitHub (Dec 4, 2023):

@StefH I tested it out and fetching the mappings works fine now, nice work!

Is the idea of this client that it should be fully compatible with standalone Wiremock instances? Because like you mention, there's no guarantee that it works, and indeed I've encountered other issues as well unfortunately. But if the intention is for it to be fully compatible it would be nice to get it working, because as far as I can tell, there doesn't seem to exist any dotnet client for standalone Wiremock.

@roengstrom commented on GitHub (Dec 4, 2023): @StefH I tested it out and fetching the mappings works fine now, nice work! Is the idea of this client that it should be fully compatible with standalone Wiremock instances? Because like you mention, there's no guarantee that it works, and indeed I've encountered other issues as well unfortunately. But if the intention is for it to be fully compatible it would be nice to get it working, because as far as I can tell, there doesn't seem to exist any dotnet client for standalone Wiremock.
Author
Owner

@StefH commented on GitHub (Dec 4, 2023):

@roengstrom

In the beginning I used the openapi-specification from WireMock.Org to generate the classes + api (I was trying to use https://github.com/StefH/RestEase-Client-Generator).

And then I did have to update some code manually to get it working.


If it's not too much work, I can try to build a 100% working .NET client, however I need to some and some help from the community for that. (I will also reach out to WireMock.Org)


So if you find other issues, please list these here, or create a PR.

@StefH commented on GitHub (Dec 4, 2023): @roengstrom In the beginning I used the openapi-specification from WireMock.Org to generate the classes + api (I was trying to use https://github.com/StefH/RestEase-Client-Generator). And then I did have to update some code manually to get it working. --- If it's not too much work, I can try to build a 100% working .NET client, however I need to some and some help from the community for that. (I will also reach out to WireMock.Org) --- So if you find other issues, please list these here, or create a PR.
Author
Owner

@roengstrom commented on GitHub (Dec 4, 2023):

@StefH I'll see if I can make time and create a PR. :) Thank you

@roengstrom commented on GitHub (Dec 4, 2023): @StefH I'll see if I can make time and create a PR. :) Thank you
Author
Owner

@StefH commented on GitHub (Dec 5, 2023):

@StefH I'll see if I can make time and create a PR. :) Thank you

Do you want to continue your PR on from my branch/PR or should I merge my PR to master so that you can fork and make your own branch?

@StefH commented on GitHub (Dec 5, 2023): > @StefH I'll see if I can make time and create a PR. :) Thank you Do you want to continue your PR on from my branch/PR or should I merge my PR to master so that you can fork and make your own branch?
Author
Owner

@roengstrom commented on GitHub (Dec 6, 2023):

@StefH I'm thinking you can merge and I'll work from master in that case.

@roengstrom commented on GitHub (Dec 6, 2023): @StefH I'm thinking you can merge and I'll work from master in that case.
Author
Owner

@StefH commented on GitHub (Dec 6, 2023):

It's merged.

@StefH commented on GitHub (Dec 6, 2023): It's merged.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#554