Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Serialization
Restling can serialize request payloads and deserialize JSON or XML responses. JSON processing supports System.Text.Json and Newtonsoft.Json.
The default value is PayloadJsonSerializerLibrary.Automatic. Restling inspects model metadata to select a serializer. If attributes from both libraries are detected, Newtonsoft.Json has priority.
RestlingClientclient=new();usingAMDevIT.Restling.Core.Serialization;RestlingClientclient=new(){SelectedDefaultSerializationLibrary=PayloadJsonSerializerLibrary.SystemTextJson};Available values are:
AutomaticNewtonsoftJsonSystemTextJson
Convenience methods accept an optional serializer override:
RestRequestResult<Customer>result=awaitclient.GetAsync<Customer>(uri,forcePayloadJsonSerializerLibrary:PayloadJsonSerializerLibrary.NewtonsoftJson,cancellationToken:cancellationToken);Advanced request objects expose ForcePayloadJsonSerializerLibrary:
RestRequestrequest=new(uri,AMDevIT.Restling.Core.HttpMethod.Get){ForcePayloadJsonSerializerLibrary=PayloadJsonSerializerLibrary.SystemTextJson};Restling uses the response Content-Type to choose the appropriate decoder. HttpMediaType provides constants such as:
HttpMediaType.ApplicationJsonHttpMediaType.ApplicationXmlHttpMediaType.ApplicationOctetStreamHttpMediaType.ApplicationFormUrlEncodedHttpMediaType.TextPlain
Set RestRequest<T>.ContentMediaType or RestRawRequest.ContentType when the request body needs an explicit type.
External entity processing is disabled by default during XML deserialization. This prevents XML External Entity (XXE) payloads from resolving external resources. See Security before changing XML or URI safety behavior.
Use GetAsync<byte[]> for binary resources. The typed Data property contains the bytes, while RawContent remains available on every result.