This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
JsonInputFormatter fails to use custom SerializerSettings #4270
Closed
Description
Using MVC as of today, March 10, 2016.
Modifiying SerializerSettings like so:
public void ConfigureServices(IServiceCollection services)
{
var mvc = services.AddMvc(config => {
ConfigureJson(config);
});
...
}
void ConfigureJson(MvcOptions config) {
var jsonSettings = new JsonSerializerSettings();
...
jsonSettings.Binder = new Json.KnownTypesSerializationBinder(KnownTypes.Map);
jsonSettings.TypeNameHandling = TypeNameHandling.All;
var jsonInputFormatters = config.InputFormatters.OfType<JsonInputFormatter>();
foreach (var jif in jsonInputFormatters)
jif.SerializerSettings = jsonSettings;
}
The custom binder is never called. It looks like the new SerializerSettings are ignored altogether.
Looking at the JsonInputFormatter code:
protected virtual JsonSerializer CreateJsonSerializer()
{
if (_jsonSerializerPool == null)
{
_jsonSerializerPool = _objectPoolProvider.Create<JsonSerializer>();
}
return _jsonSerializerPool.Get();
}
I don't see how the SerializerSettings get applied.
This is in contrast to the JsonOutputFormatter:
protected virtual JsonSerializer CreateJsonSerializer()
{
if (_serializer == null)
{
_serializer = JsonSerializer.Create(SerializerSettings);
}
return _serializer;
}