Microsoft.Azure.Core.NewtonsoftJson
2.0.0
Prefix Reserved
dotnet add package Microsoft.Azure.Core.NewtonsoftJson --version 2.0.0
NuGet\Install-Package Microsoft.Azure.Core.NewtonsoftJson -Version 2.0.0
<PackageReference Include="Microsoft.Azure.Core.NewtonsoftJson" Version="2.0.0" />
paket add Microsoft.Azure.Core.NewtonsoftJson --version 2.0.0
#r "nuget: Microsoft.Azure.Core.NewtonsoftJson, 2.0.0"
// Install Microsoft.Azure.Core.NewtonsoftJson as a Cake Addin #addin nuget:?package=Microsoft.Azure.Core.NewtonsoftJson&version=2.0.0 // Install Microsoft.Azure.Core.NewtonsoftJson as a Cake Tool #tool nuget:?package=Microsoft.Azure.Core.NewtonsoftJson&version=2.0.0
Newtonsoft.Json support for Azure Core shared client library for .NET
The Azure.Core package contains types shared by the latest Azure SDK client libraries. This Newtonsoft.Json
compatibility library:
- Contains converters dependent upon the Newtonsoft.Json package.
- Enables serialization and deserialization of custom model types using
Newtonsoft.Json
. Those custom model types may then be used with the following client libraries:
Getting started
Install the package
Install this package from NuGet using the .NET CLI:
dotnet add package Microsoft.Azure.Core.NewtonsoftJson
Key concepts
This support package contains the NewtonsoftJsonObjectSerializer
class which can be passed to some Azure SDKs' client options classes, as shown in the examples below.
The following converters are added automatically to the NewtonsoftJsonObjectSerializer
if you do not pass your own JsonSerializerSettings
:
NewtonsoftJsonETagConverter
to convertAzure.ETag
properties.
See the example Using default converters below for getting an instance of JsonSerializerSettings
with this default list you can then modify as needed.
Examples
The Azure.Search.Documents package is used in examples to show how search results can be deserialized. For more information and examples using Azure.Search.Documents, see its README.
Deserializing models
Consider a custom model class containing information about movies:
public class Movie
{
[JsonProperty("uuid")]
public string Id { get; private set; } = Guid.NewGuid().ToString();
public string Title { get; set; }
public string Description { get; set; }
public float Rating { get; set; }
}
Our Azure Cognitive Search index is defined using camelCase fields, and the Id
field is actually defined as "uuid"; however, we can provide an idiomatic model without having to attribute all properties by setting the JsonSerializerSettings.ContractResolver
property as shown below:
// Get the Azure Cognitive Search endpoint and read-only API key.
Uri endpoint = new Uri(Environment.GetEnvironmentVariable("SEARCH_ENDPOINT"));
AzureKeyCredential credential = new AzureKeyCredential(Environment.GetEnvironmentVariable("SEARCH_API_KEY"));
// Create serializer options with default converters for Azure SDKs.
JsonSerializerSettings serializerSettings = NewtonsoftJsonObjectSerializer.CreateJsonSerializerSettings();
// Serialize property names using camelCase by default.
serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
SearchClientOptions clientOptions = new SearchClientOptions
{
Serializer = new NewtonsoftJsonObjectSerializer(serializerSettings)
};
SearchClient client = new SearchClient(endpoint, "movies", credential, clientOptions);
Response<SearchResults<Movie>> results = client.Search<Movie>("Return of the King");
foreach (SearchResult<Movie> result in results.Value.GetResults())
{
Movie movie = result.Document;
Console.WriteLine(movie.Title);
Console.WriteLine(movie.Description);
Console.WriteLine($"Rating: {movie.Rating}\n");
}
If searching an index full of movies, the following may be printed:
The Lord of the Rings: The Return of the King
Gandalf and Aragorn lead the World of Men against Sauron's army to draw his gaze from Frodo and Sam as they approach Mount Doom with the One Ring.
Rating: 9.1
Using default converters
If you instantiate a NewtonsoftJsonObjectSerializer
using the default constructor, some converters for common Azure SDKs are added automatically as listed above in Key concepts. To modify these default settings, you can create a new JsonSerializerSettings
like in the following example:
JsonSerializerSettings serializerSettings = NewtonsoftJsonObjectSerializer.CreateJsonSerializerSettings();
// Serialize property names using camelCase by default.
serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
// Add converters as needed, for example, to convert movie genres to an enum.
serializerSettings.Converters.Add(new StringEnumConverter());
SearchClientOptions clientOptions = new SearchClientOptions
{
Serializer = new NewtonsoftJsonObjectSerializer(serializerSettings)
};
You can add or remove converters, set the ContractResolver
, or any other members of JsonSerializerSettings
you need.
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Azure.Core (>= 1.36.0)
- Newtonsoft.Json (>= 13.0.1)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on Microsoft.Azure.Core.NewtonsoftJson:
Package | Downloads |
---|---|
Microsoft.Azure.SignalR.Management
Provides communication capabilities with ASP.NET Core SignalR clients through Azure SignalR Service directly. The capabilities include sending messages to all/clients/users/groups and managing group membership. For more information, see https://github.com/Azure/azure-signalr/blob/dev/docs/management-sdk-guide.md |
|
Microsoft.Azure.Functions.Worker.Extensions.OpenApi
This package helps render OpenAPI document and Swagger UI of Azure Functions endpoints through the out-of-process worker. |
|
Dan.Common
This package includes the common models and utilities used for communicating between Dan.Core and the various Dan plugins and simplifying plugin development. |
|
FakeHttpRequestData
A library containing a fake implementation of HttpRequestData that can be used for unit testing. |
|
lgp1985.Azure.Functions.Worker.Extensions.OpenApi
This package helps render OpenAPI document and Swagger UI of Azure Functions endpoints through the out-of-process worker. |
GitHub repositories (4)
Showing the top 4 popular GitHub repositories that depend on Microsoft.Azure.Core.NewtonsoftJson:
Repository | Stars |
---|---|
Azure/azure-sdk-for-net
This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
|
|
Azure/azure-functions-dotnet-worker
Azure Functions out-of-process .NET language worker
|
|
Azure/azure-signalr
Azure SignalR Service SDK for .NET
|
|
Azure/azure-functions-openapi-extension
This extension provides an Azure Functions app with Open API capability for better discoverability to consuming parties
|
Version | Downloads | Last updated |
---|---|---|
2.0.0 | 997,089 | 12/14/2023 |
1.0.0 | 11,038,550 | 1/8/2021 |
1.0.0-preview.1 | 1,897 | 8/7/2020 |