scott-mcdonald / JsonApiFramework

JsonApiFramework is a fast, extensible, and portable .NET framework for the reading and writing of JSON API documents. Currently working on ApiFramework 1.0 which is a new framework that supports the many enhancements documented in the 2.0 milestone of this project while being media type agnostic but will support media types like {json:api} and GraphQL for serialization/deserialization purposes.
Other
96 stars 11 forks source link

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

Open yurii-pelekh opened 4 years ago

yurii-pelekh commented 4 years ago

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

skolima commented 4 years ago

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:

related:

RichardsonWTR commented 4 years ago

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 commented 4 years ago

We also just hit this in .Net Core 3 😅

twcrews commented 2 months ago

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 commented 2 months ago

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