Serialize (JsonSerializer)¶
JsonSerializer.Serialize is the RestSharp.Serializers.ISerializer adapter method RestSharp calls to turn a request body object into the JSON text sent on the wire, using a fixed set of Newtonsoft.Json settings configured at construction.
| Field | Value |
|---|---|
| Operation ID | OP-10 |
| Trigger | RestSharp invokes it when AddJsonBody content is written (GetJsonResponse steps 5–6). |
| Inputs | object obj (the request body). |
| Outputs | The serialized JSON string. |
| Primary components | SAIF.Web.API.Clients.JsonSerializer.Serialize(object) |
| Entry point | src/SAIF.Web.API.Clients/JsonSerializer.cs |
Steps¶
- (Constructor) Set
ContentType = "application/json"and build an internal Newtonsoft serializer withMissingMemberHandling.Ignore,NullValueHandling.Include,DefaultValueHandling.Include, and the caller'sDateTimeZoneHandling(BR-CLI-011). - The two-argument constructor overload replaces all of these settings with a caller-supplied
Newtonsoft.Json.JsonSerializerinstead. - Open a
StringWriter→JsonTextWriterwithFormatting.IndentedandQuoteChar = '"'. - Payloads are pretty-printed on the wire, producing larger request bodies than a compact serialization would.
_serializer.Serialize(jsonTextWriter, obj)and return the accumulated string (BR-CLI-011).- On failure: serialization exceptions propagate uncaught to the caller.
Process flow¶
flowchart TD
Start([Serialize called]) --> Writer["Open StringWriter /<br>JsonTextWriter,<br>Formatting.Indented"]
Writer --> Serialize["Newtonsoft serializer<br>writes obj"]
Serialize --> EndOk([Return JSON string])
Failure and edge-case behavior¶
- Serialization exceptions (for example from a non-serializable object graph) propagate uncaught to the calling
RestRequest/GetJsonResponsechain.
Related documentation¶
Sources¶
src/SAIF.Web.API.Clients/JsonSerializer.cs