You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
To reproduce, configure a custom JsonOutputFormatter in Startup.cs as follows:
services.AddMvc().Configure<MvcOptions>(options =>
{
var formatter = new JsonOutputFormatter();
formatter.SerializerSettings = new JsonSerializerSettings();
formatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
options.OutputFormatters.Clear();
options.OutputFormatters.Add(formatter);
});
In the first two requests, the custom settings are used, and the returned properties are camel case. After the first two requests, the settings are not respected, and the default json formatter settings are used.
I have tracked the problem to CanWriteResult() in OutputFormatter.cs. In the first request, the SupportedMediaTypes reads as follows:
Note the index change. The first supported media type is not found anymore. From now on the SupportedMediaTypes are fully populated with Charset data, and the custom json formatter is not found by the .FirstOrDefault().
The text was updated successfully, but these errors were encountered:
@rmja thanks for the thorough report. It looks like the issue might be in OutputFormatter@192.
var selectedMediaType = context.SelectedContentType;
// If content type is not set then set it based on supported media types.
selectedMediaType = selectedMediaType ?? SupportedMediaTypes.FirstOrDefault();
<skipping over a few lines...>
context.SelectedEncoding = selectedEncoding;
// Override the content type value even if one already existed.
selectedMediaType.Charset = selectedEncoding.WebName;
selectedEncoding might refer to one of the values from SupportedMediaTypes. We should be making a copy before mutating it.
To reproduce, configure a custom JsonOutputFormatter in Startup.cs as follows:
In the first two requests, the custom settings are used, and the returned properties are camel case. After the first two requests, the settings are not respected, and the default json formatter settings are used.
I have tracked the problem to CanWriteResult() in OutputFormatter.cs. In the first request, the SupportedMediaTypes reads as follows:
and
In the 2nd request, the SupportedMediaTypes reads as follows:
In this case:
Note the index change. The first supported media type is not found anymore. From now on the SupportedMediaTypes are fully populated with Charset data, and the custom json formatter is not found by the
.FirstOrDefault()
.The text was updated successfully, but these errors were encountered: