Open ckuetbach opened 1 year ago
Hey Christian. This is actually just an unfortunate difference between System.Text.Json and System.Net.Http. The latter uses System.Text.Json's "web" defaults, which camel-cases property names.
ReturnsJsonResponse uses System.Net.Http.Json.JsonContent internally, so unless you specify your own JsonSerializerOptions, it'll end up camel casing, which is fine if you're also using the extension methods from System.Net.Http, like GetFromJsonAsync(), but if you use System.Text.Json directly to deserialize the JsonContent, you'll need to either reset the serializer options back to System.Text.Json's defaults as you did or specify the web defaults when deserializing, like so:
var actual = await JsonSerializer.DeserializeAsync<List<Song>>(actualBody,
new JsonSerializerOptions(JsonSerializerDefaults.Web));
Hi Max, thanks for you reply.
That makes totally sense. I usually worked with newtonsoft json and its deserializer was case-insensitive.
I'm wondering why the web-defauls are Case-Insensitive // PropertyNameCaseInsensitive: True
and it is still an issue:
If a Https calls
Content.ReadAsStreamAsync()
to get the Content and deserialize that Value, the returned object only contains null-values.I created a Unit Test for this Issue:
If I call
.ReturnsJsonResponse(HttpStatusCode.OK, expectedResponse, new JsonSerializerOptions());
and provide any JsonSerializerOptions, the tests works s expected.I'm not sure, if this is an actual error or a misleading documentation or
ReturnsJsonResponse