When posting new mapping, use DateParseHandling.None (#348)

* .

* OfType + test

* remove line
This commit is contained in:
Stef Heyenrath
2019-09-20 13:44:19 +02:00
committed by GitHub
parent 9cd16f726f
commit 666992ef24
6 changed files with 52 additions and 22 deletions

View File

@@ -57,6 +57,8 @@ namespace WireMock.Util
new WildcardMatcher("application/x-www-form-urlencoded", true)
};
private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings { DateParseHandling = DateParseHandling.None };
public static bool ShouldParseBody([CanBeNull] string method)
{
if (string.IsNullOrEmpty(method))
@@ -135,12 +137,12 @@ namespace WireMock.Util
data.Encoding = DefaultEncoding;
data.DetectedBodyType = BodyType.String;
// If string is not null or empty, try to get as Json
// If string is not null or empty, try to deserialize the string to a JObject
if (!string.IsNullOrEmpty(data.BodyAsString))
{
try
{
data.BodyAsJson = JsonConvert.DeserializeObject(data.BodyAsString, new JsonSerializerSettings { Formatting = Formatting.Indented });
data.BodyAsJson = JsonConvert.DeserializeObject(data.BodyAsString, JsonSerializerSettings);
data.DetectedBodyType = BodyType.Json;
}
catch