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

Move from Newtonsoft.Json to System.Text.Json #67

Open
yurii-pelekh opened this issue Nov 5, 2019 · 5 comments
Open

Move from Newtonsoft.Json to System.Text.Json #67

yurii-pelekh opened this issue Nov 5, 2019 · 5 comments

Comments

@yurii-pelekh
Copy link

Hi Scott
It would be perfect to move to the new (de)serialization library. Do you have any plans for that?

@skolima
Copy link

skolima commented Jan 2, 2020

Note: because of the hard dependency on Newtonsoft.Json, out of the box JsonApiFramework does not behave as expected on .NET Core 3.0/3.1 (the serialisation format doesn't match as Newtonsoft.Json attributes are ignored).

A workaround exists:

  • add dependency on Microsoft.AspNetCore.Mvc.NewtonsoftJson
  • call services.AddControllers().AddNewtonsoftJson(); instead of just AddControllers() in Startup

related:

@RichardsonWTR
Copy link

RichardsonWTR commented Jul 31, 2020

For what it's worth.

I was testing the Blogging Web Service example from the repo JsonApiFramework.Samples.
The project was originally made for .net core 2.2, but I changed it to 3.1.
I knew I shoudn't have changed it but it was just a test anyway. "Lets try it out and see what happens", I thought.

I was getting weird responses like (below a small piece of a response)

"jsonApiVersion": {
    "version": "1.0",
    "meta": null
  },
"attributes": [
      {
        "name": "firstName"
      },
      {
        "name": "lastName"
      },
      {
        "name": "twitter"
      }
    ]

And when I added .AddNewtonsoftJson() to .AddControllers() , everything worked as expected:

"jsonapi": {
    "version": "1.0"
  },
"attributes": {
      "firstName": "Sina",
      "lastName": "Pesantes",
      "twitter": "@spesantes"
    }

Thanks skolima for your comment above.
Maybe this comment will be useful for someone trying to use this library with .net core 3.1.

How to fix this?

Until the Newtonsoft.json dependency is in the code I think would be useful throw an exception if the serializer is not configured properly.

@abbottdev
Copy link

We also just hit this in .Net Core 3 😅

@twcrews
Copy link

twcrews commented Aug 19, 2024

I am getting close(ish) to an implementation in #99. It's a heavier lift than it seems, as System.Text.Json is architecturally very different from Newtonsoft.Json.

At this point, I'm just working on getting tests to pass. I welcome anyone who wants to give it a look, esp. @scott-mcdonald. 🤞

@scott-mcdonald
Copy link
Owner

For your edification @twcrews , please see my comment here discussing how this request should probably be architected and implemented.

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

6 participants