Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

[FYI] Package doesn't serialize anymore, but you won't believe what RestSharp did next! #11

Closed
beeradmoore opened this issue Jan 17, 2019 · 1 comment

Comments

@beeradmoore
Copy link

So we came across something odd today, we our json serialisation seemed to not work with RestSharp 106.6 (I think that is about what we are on), but deserialisation works. After some hunting around and trying to figure out what is wrong we came across RestSharps new ReadMe (as of Jan 1st) which pretty much says "Whops, Json.NET is coming back".

The juicy bits are as below.

Note on JSON serialization

Some time ago, we have decided to get rid of the reference to Newtonsoft.Json package.
The intentions were good, we thought that the SimpleJson library would be a good replacement that can be embedded to the library itself,
so we don't need to have any external references.

However, as many good intentions, that change created more issues than it solved. The number of issues on GitHub that are
related to JSON (de)serialization is growing and SimpleJson is long abandoned. We faced a choice to start maintaining
SimpleJson ourselves or use something else.

Since as per today almost every .NET project has a direct or indirect reference to Newtonsoft.Json, we decided to bring it back as a dependency
and get rid of SimpleJson. This will be done in RestSharp v107, the next major version.

To prepare for this change, we made quite a few changes in how serialization works in RestSharp. Before, objects were serialized
when added to the RestRequest by using one of the AddBody methods. That made it impossible to assign a custom
serializer on the client level, so it should have been done for each request. In v106.6 body parameter is serialized just
before executing the request. Delaying the serialization allowed us to add the client-level serializer.

It is still possible to assign custom (de)serializer per request, as before. In addition to that, you can
use the new method IRestClient.UseSerializer(IRestSerializer restSerializer). The IRestSerializer interface
has methods for serialization and deserialization. Default serializers are the same as before.

From v106.6.2 you can use Newtonsoft.Json for the RestClient by using code from this snippet.

@adamfisher
Copy link
Owner

Thank you for that information! Glad to see they are bringing it back. I have decided to discontinue maintaining this package and deprecate it.

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

No branches or pull requests

2 participants