Skip to content

Aspnet Core Integration Uses Obsolete Constructor #95

@jordannb

Description

@jordannb

Issue refers to the following documentation: https://github.com/codecutout/JsonApiSerializer#integrating-with-microsoftaspnetcoremvc

Documentation recommends newing up JsonInputFormatter with JsonInputFormatter(ILogger, JsonSerializerSettings, ArrayPool<char>, ObjectPoolProvider) constructor (JsonInputFormatter`4). Per Microsoft, this constructor is now obsoleted: https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.formatters.jsoninputformatter.-ctor?view=aspnetcore-2.2#Microsoft_AspNetCore_Mvc_Formatters_JsonInputFormatter__ctor_Microsoft_Extensions_Logging_ILogger_Newtonsoft_Json_JsonSerializerSettings_System_Buffers_ArrayPool_System_Char__Microsoft_Extensions_ObjectPool_ObjectPoolProvider_

It is still possible to use this constructor, but due to likelihood that it will be removed from future versions of of dotnet, I am looking for a better/more future-proof way of integrating. The only remaining non-obsolete constructor requires passing both MvcOptions (available in IServiceCollection.AddMvc`1) and MvcJsonOptions (available in IMvcBuilder.AddJsonOptions`1)), but I've not yet found a way to access both MvcOptions and MvcJsonOptions in the same place in order to use the preferred constructor.

Though this is not definitive, it appears that Microsoft intends that custom serialization settings be achieved via IMvcBuilder.AddJsonOptions`1: aspnet/Mvc#4339 (comment)

I will follow up if I find a good solution for integrating with Aspnet Core WebApi that doesn't go against current "best practices", but wanted to post here as well in case it is relevant to others.

Thanks.
~Jordan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions