Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aspnet Core Integration Uses Obsolete Constructor #95

Open
jordannb opened this issue Mar 6, 2019 · 1 comment
Open

Aspnet Core Integration Uses Obsolete Constructor #95

jordannb opened this issue Mar 6, 2019 · 1 comment

Comments

@jordannb
Copy link

jordannb commented Mar 6, 2019

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

@alex-davies
Copy link
Collaborator

Thanks @jordannb for highlighting that, may need to update the docs with an alternate less deprecated way to set the serialise.

I believe there is something in #58. However need some more investigation why it is causing different serialization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants