mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-24 09:48:51 +02:00
@@ -252,7 +252,7 @@ namespace WireMock.ResponseBuilders
|
|||||||
|
|
||||||
case BodyDestinationFormat.Json:
|
case BodyDestinationFormat.Json:
|
||||||
ResponseMessage.BodyData.DetectedBodyType = BodyType.Json;
|
ResponseMessage.BodyData.DetectedBodyType = BodyType.Json;
|
||||||
ResponseMessage.BodyData.BodyAsJson = JsonConvert.DeserializeObject(body);
|
ResponseMessage.BodyData.BodyAsJson = JsonUtils.DeserializeObject(body);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
using JetBrains.Annotations;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -5,9 +8,6 @@ using System.Linq;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Admin.Scenarios;
|
using WireMock.Admin.Scenarios;
|
||||||
using WireMock.Admin.Settings;
|
using WireMock.Admin.Settings;
|
||||||
@@ -179,8 +179,10 @@ namespace WireMock.Server
|
|||||||
|
|
||||||
_settings.Logger.Info($"Watching folder '{folder}'{includeSubdirectoriesText} for new, updated and deleted MappingFiles.");
|
_settings.Logger.Info($"Watching folder '{folder}'{includeSubdirectoriesText} for new, updated and deleted MappingFiles.");
|
||||||
|
|
||||||
var watcher = new EnhancedFileSystemWatcher(folder, "*.json", EnhancedFileSystemWatcherTimeoutMs);
|
var watcher = new EnhancedFileSystemWatcher(folder, "*.json", EnhancedFileSystemWatcherTimeoutMs)
|
||||||
watcher.IncludeSubdirectories = includeSubdirectories;
|
{
|
||||||
|
IncludeSubdirectories = includeSubdirectories
|
||||||
|
};
|
||||||
|
|
||||||
watcher.Created += (sender, args) =>
|
watcher.Created += (sender, args) =>
|
||||||
{
|
{
|
||||||
@@ -229,7 +231,7 @@ namespace WireMock.Server
|
|||||||
|
|
||||||
if (FileHelper.TryReadMappingFileWithRetryAndDelay(_settings.FileSystemHandler, path, out string value))
|
if (FileHelper.TryReadMappingFileWithRetryAndDelay(_settings.FileSystemHandler, path, out string value))
|
||||||
{
|
{
|
||||||
var mappingModels = DeserializeObjectToArray<MappingModel>(JsonConvert.DeserializeObject(value));
|
var mappingModels = DeserializeObjectToArray<MappingModel>(JsonUtils.DeserializeObject(value));
|
||||||
foreach (var mappingModel in mappingModels)
|
foreach (var mappingModel in mappingModels)
|
||||||
{
|
{
|
||||||
if (mappingModels.Length == 1 && Guid.TryParse(filenameWithoutExtension, out Guid guidFromFilename))
|
if (mappingModels.Length == 1 && Guid.TryParse(filenameWithoutExtension, out Guid guidFromFilename))
|
||||||
@@ -882,7 +884,7 @@ namespace WireMock.Server
|
|||||||
{
|
{
|
||||||
if (requestMessage?.BodyData?.DetectedBodyType == BodyType.String)
|
if (requestMessage?.BodyData?.DetectedBodyType == BodyType.String)
|
||||||
{
|
{
|
||||||
return JsonConvert.DeserializeObject<T>(requestMessage.BodyData.BodyAsString);
|
return JsonUtils.DeserializeObject<T>(requestMessage.BodyData.BodyAsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestMessage?.BodyData?.DetectedBodyType == BodyType.Json)
|
if (requestMessage?.BodyData?.DetectedBodyType == BodyType.Json)
|
||||||
|
|||||||
@@ -57,8 +57,6 @@ namespace WireMock.Util
|
|||||||
new WildcardMatcher("application/x-www-form-urlencoded", true)
|
new WildcardMatcher("application/x-www-form-urlencoded", true)
|
||||||
};
|
};
|
||||||
|
|
||||||
private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings { DateParseHandling = DateParseHandling.None };
|
|
||||||
|
|
||||||
public static bool ShouldParseBody([CanBeNull] string httpMethod, bool allowBodyForAllHttpMethods)
|
public static bool ShouldParseBody([CanBeNull] string httpMethod, bool allowBodyForAllHttpMethods)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(httpMethod))
|
if (string.IsNullOrEmpty(httpMethod))
|
||||||
@@ -147,7 +145,7 @@ namespace WireMock.Util
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
data.BodyAsJson = JsonConvert.DeserializeObject(data.BodyAsString, JsonSerializerSettings);
|
data.BodyAsJson = JsonUtils.DeserializeObject(data.BodyAsString);
|
||||||
data.DetectedBodyType = BodyType.Json;
|
data.DetectedBodyType = BodyType.Json;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
@@ -25,6 +25,28 @@ namespace WireMock.Util
|
|||||||
return JsonConvert.DeserializeObject<JToken>(json, JsonSerializerSettings);
|
return JsonConvert.DeserializeObject<JToken>(json, JsonSerializerSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deserializes the JSON to a .NET object.
|
||||||
|
/// Using : DateParseHandling = DateParseHandling.None
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="json">A System.String that contains JSON.</param>
|
||||||
|
/// <returns>The deserialized object from the JSON string.</returns>
|
||||||
|
public static object DeserializeObject(string json)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject(json, JsonSerializerSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deserializes the JSON to the specified .NET type.
|
||||||
|
/// Using : DateParseHandling = DateParseHandling.None
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="json">A System.String that contains JSON.</param>
|
||||||
|
/// <returns>The deserialized object from the JSON string.</returns>
|
||||||
|
public static T DeserializeObject<T>(string json)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject<T>(json, JsonSerializerSettings);
|
||||||
|
}
|
||||||
|
|
||||||
public static T ParseJTokenToObject<T>(object value)
|
public static T ParseJTokenToObject<T>(object value)
|
||||||
{
|
{
|
||||||
switch (value)
|
switch (value)
|
||||||
|
|||||||
Reference in New Issue
Block a user