mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-05-30 02:20:41 +02:00
Add SystemTextJsonMatchers (#1447)
* SystemTextJsonMatcher * , * . * new projectx * Update test/WireMock.Net.Tests/Pact/PactTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update test/WireMock.Net.Tests/WebSockets/WebSocketIntegrationTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/WireMock.Net/WireMock.Net.csproj Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/WireMock.Net.Minimal/Properties/AssemblyInfo.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * . * more tests * . * . * x * ... * . * fix tests * 0.11.0 * . * delete jsonutils.cs * s * fix findings * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> * Potential fix for pull request finding 'Missing Dispose call on local IDisposable' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> * JsonConverter 0.12.0 * -- tools --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
This commit is contained in:
@@ -3,12 +3,14 @@
|
||||
using System.Collections;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using JsonConverter.Newtonsoft.Json;
|
||||
using JsonConverter.System.Text.Json;
|
||||
using Stef.Validation;
|
||||
using WireMock.Constants;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Models;
|
||||
using WireMock.Transformers;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
|
||||
@@ -57,11 +59,9 @@ public static class WireMockServerSettingsParser
|
||||
DisableRequestBodyDecompressing = parser.GetBoolValue(nameof(WireMockServerSettings.DisableRequestBodyDecompressing)),
|
||||
DisableDeserializeFormUrlEncoded = parser.GetBoolValue(nameof(WireMockServerSettings.DisableDeserializeFormUrlEncoded)),
|
||||
DoNotSaveDynamicResponseInLogEntry = parser.GetBoolValue(nameof(WireMockServerSettings.DoNotSaveDynamicResponseInLogEntry)),
|
||||
GraphQLSchemas = parser.GetObjectValueFromJson<Dictionary<string, GraphQLSchemaDetails>>(nameof(settings.GraphQLSchemas)),
|
||||
HandleRequestsSynchronously = parser.GetBoolValue(nameof(WireMockServerSettings.HandleRequestsSynchronously)),
|
||||
HostingScheme = parser.GetEnumValue<HostingScheme>(nameof(WireMockServerSettings.HostingScheme)),
|
||||
MaxRequestLogCount = parser.GetIntValue(nameof(WireMockServerSettings.MaxRequestLogCount)),
|
||||
ProtoDefinitions = parser.GetObjectValueFromJson<Dictionary<string, string[]>>(nameof(settings.ProtoDefinitions)),
|
||||
QueryParameterMultipleValueSupport = parser.GetEnumValue<QueryParameterMultipleValueSupport>(nameof(WireMockServerSettings.QueryParameterMultipleValueSupport)),
|
||||
ReadStaticMappings = parser.GetBoolValue(nameof(WireMockServerSettings.ReadStaticMappings)),
|
||||
RequestLogExpirationDuration = parser.GetIntValue(nameof(WireMockServerSettings.RequestLogExpirationDuration)),
|
||||
@@ -80,6 +80,7 @@ public static class WireMockServerSettingsParser
|
||||
settings.AcceptAnyClientCertificate = parser.GetBoolValue(nameof(WireMockServerSettings.AcceptAnyClientCertificate));
|
||||
#endif
|
||||
|
||||
ParseJsonSerializerSettings(settings, parser);
|
||||
ParseLoggerSettings(settings, logger, parser);
|
||||
ParsePortSettings(settings, parser);
|
||||
ParseProxyAndRecordSettings(settings, parser);
|
||||
@@ -88,6 +89,9 @@ public static class WireMockServerSettingsParser
|
||||
ParseActivityTracingSettings(settings, parser);
|
||||
ParseWebSocketSettings(settings, parser);
|
||||
|
||||
settings.GraphQLSchemas = parser.GetObjectValueFromJson<Dictionary<string, GraphQLSchemaDetails>>(nameof(settings.GraphQLSchemas), settings.DefaultJsonSerializer);
|
||||
settings.ProtoDefinitions = parser.GetObjectValueFromJson<Dictionary<string, string[]>>(nameof(settings.ProtoDefinitions), settings.DefaultJsonSerializer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -259,4 +263,21 @@ public static class WireMockServerSettingsParser
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static void ParseJsonSerializerSettings(WireMockServerSettings settings, SimpleSettingsParser parser)
|
||||
{
|
||||
var defaultJsonSerializer = parser.GetStringValue(nameof(WireMockServerSettings.DefaultJsonSerializer));
|
||||
settings.DefaultJsonSerializer = defaultJsonSerializer switch
|
||||
{
|
||||
nameof(SystemTextJsonConverter) => new SystemTextJsonConverter(),
|
||||
_ => new NewtonsoftJsonConverter(),
|
||||
};
|
||||
|
||||
var defaultJsonBodyTransformer = parser.GetStringValue(nameof(WireMockServerSettings.DefaultJsonBodyTransformer));
|
||||
settings.DefaultJsonBodyTransformer = defaultJsonBodyTransformer switch
|
||||
{
|
||||
nameof(SystemTextJsonBodyTransformer) => new SystemTextJsonBodyTransformer(settings),
|
||||
_ => new NewtonsoftJsonBodyTransformer(settings),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user