Coder Social home page Coder Social logo

adamfisher / restsharp.serializers.newtonsoft.json Goto Github PK

View Code? Open in Web Editor NEW
40.0 7.0 7.0 28 KB

Restores Newtonsoft.JSON as the default serializer for RestSharp.

License: Apache License 2.0

C# 100.00%
restsharp newtonsoft-json json-serialization json serialization

restsharp.serializers.newtonsoft.json's Introduction

RestSharp.Serializers.Newtonsoft.Json

DEPRECATED -- This library is no longer necessary since RestSharp has decided to bring back Newtonsoft.JSON support in v107.0. If you are using a version of RestSharp earlier than that, then this library may still be useful to you but will be unmaintained.

This is a glue library that makes Newtonsoft.JSON the default serializer for RestSharp.

RestSharp removed Newtonsoft.JSON as a dependency in version 103.0 which is great if you don't need all the extra capability Newtonsoft.JSON provides.

After working on several projects and getting annoyed with the limited functionality available in the default JsonSerializer include with .NET, I decided to create this project so I wouldn't have to leave a JSON serialization implementation laying around in my projects. Hopefully it helps someone else too.

Getting Started

Installation

This package is available as a nuget package on nuget.org.

Code

This library makes a NewtonsoftJsonSerializer available which you can readily plug into your RestSharp request object like this:

var request = new RestRequest();
request.JsonSerializer = new NewtonsoftJsonSerializer();

If you don't want to keep initializing every RestRequest, you can also use the RestSharp.Serializers.Newtonsoft.Json.RestRequest class instead of the one from RestSharp. They are named the same but this class will default to using the Newtonsoft.JSON serialization engine.

restsharp.serializers.newtonsoft.json's People

Contributors

adamfisher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

restsharp.serializers.newtonsoft.json's Issues

Net standard support not working

I think you need to update the dependency on Rest Sharp from 105.2.3 (which does not net standard) to 106.0.1.

Currently installing this package generates a warning:

Package 'RestSharp 105.2.3' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.

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

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.

No longer installs on .NET 4.6

Hello,

I've been using this for a project of mine in VS 2015 via Nuget. I've attempted to update the package but I keep getting an error message to say that the package is no longer compatible due to the package being no longer compatible with .NET 4.6 (see screenshot)

image

I've had a look at your package via Nuget Package Explorer and it seems its missing the necessary libraries for .NET 4.6. Can this be rectified at all?

Many thanks

NuGet package deprecation

Thank you for helping the RestSharp community to use NewtonsoftJson serializer.

I have completed the work to support NewtonsoftJson in the core repository, but I decided to use a separate package. However, I am unable to publish the package because it conflicts with your package name. My package is called RestSharp.NewtonsoftJson and NuGet complains that it is too similar to yours.

Do you have an idea how can we solve this issue? I don't want to create issues for all those people who use your package.

Cannot resolve the reference

Hi Adam,
I am using NewtonSoft.Json 12.0.1, RestSharp 106.5.4 and RestSharp.Newtonsoft.Json 1.5.0 in my application. IOS is working properly in simulator. I get an error when I want to try the iPhone. First, I tried the NewtonSoft version 11.0.2 and got the same error. The problem is fixed when I make the version 12.0.1 and lower the RestSharp version to 106.0.1. Because the error message 106.0.1 has given warning. I hope I can tell in a clear way.

Error message

Error MT2101: Cannot resolve the reference 'System.Void RestSharp.RestRequest ::. Ctor (System.String)', referenced from the method 'System.Void RestSharp.Serializers.Newtonsoft.Json.RestRequest ::. Ctor (System .String) '' RestSharp, Version = 106.0.1.0, Culture = neutral, PublicKeyToken = 598062e77f915f75 '. (MT2101) (crmmobile.iOS)

strongname

Is it possible to create a StrongName version type ?

No deserializer?

Is there a specific reason why you don't also include a deserializer as well?
Would be nice to get an all in one solution.

Specifically, I don't like how the default RestSharp deserializer doesn't support enums the same way as json.net

Request Upgrade to .NET Standard 2.0

For those of us using WPF on .NET 4.6.1 an upgrade to the recently released .NET Standard 2.0 is necessary to replace Ver 1.1 of this library

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.