Mvc: replace serializerSettings on JsonInputFormatter

Created on 27 May 2016  路  1Comment  路  Source: aspnet/Mvc

I am not sure if I am doing it correct but on rc2-final release, this is how I am changing the serializerSettings on JsonInputFormatter:

        private void ConfigureFormatters(MvcOptions options)
        {
            var serializerSettings = SerializerSettingsProvider.CreateSerializerSettings();
            serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            var jsonInputFormatter = new JsonInputFormatter(
                _loggerFactory.CreateLogger<JsonInputFormatter>(), 
                serializerSettings, 
                ArrayPool<char>.Shared, 
                new DefaultObjectPoolProvider());

            options.InputFormatters.RemoveType<JsonInputFormatter>();
            options.InputFormatters.Insert(0, jsonInputFormatter);
        }

which is a bit different than RC1 where the JsonInputFormatter constructor only accepted serializerSettings and now, I also care about arrayPool and pool provider. Is this is the way to replace the settings or is there a more unobtrusive way to do this?

question

Most helpful comment

@tugberkugurlu should be cleaner to add the following to your Startup.ConfigureServices() method:

c# services .AddMvc() .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver());

>All comments

@tugberkugurlu should be cleaner to add the following to your Startup.ConfigureServices() method:

c# services .AddMvc() .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver());

Was this page helpful?
0 / 5 - 0 ratings