C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
AnalyzeReJsonConverter.cs
Go to the documentation of this file.
1using System;
2using System.Globalization;
3
4using Newtonsoft.Json;
5using Newtonsoft.Json.Converters;
6using RestSharp;
7using IDeserializer = RestSharp.Deserializers.IDeserializer;
8using ISerializer = RestSharp.Serializers.ISerializer;
9
11{
18 {
21
22 #region Serializer Settings
23 private static JsonSerializerSettings _defaultDeserializerSettings;
27 public static JsonSerializerSettings DefaultDeserializerSettings =>
28 _defaultDeserializerSettings ?? (_defaultDeserializerSettings =
29 new JsonSerializerSettings
30 {
31 Culture = CultureInfo.InvariantCulture,
32 DateFormatHandling = DateFormatHandling.IsoDateFormat,
33 DateParseHandling = DateParseHandling.None,
34 DateTimeZoneHandling = DateTimeZoneHandling.Utc,
35 FloatFormatHandling = FloatFormatHandling.Symbol,
36 NullValueHandling = NullValueHandling.Ignore,
37 Converters = new JsonConverter[]
38 {
40 new StringEnumConverter(),
43 // Allow creating any other APIType object.
45 // Handle nested object dictionaries and lists (e.g. for metadata)
47 new UriConverter(),
48 },
49 ContractResolver = new RespectIgnoreDataMemberResolver()
50 });
51
52 private static JsonSerializerSettings _defaultSerializerSettings;
56 public static JsonSerializerSettings DefaultSerializerSettings =>
57 _defaultSerializerSettings ?? (_defaultSerializerSettings =
58 new JsonSerializerSettings
59 {
60 Culture = CultureInfo.InvariantCulture,
61 DateFormatHandling = DateFormatHandling.IsoDateFormat,
62 DateTimeZoneHandling = DateTimeZoneHandling.Utc,
63 ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
64 FloatFormatHandling = FloatFormatHandling.Symbol,
65 NullValueHandling = NullValueHandling.Ignore,
66 Converters = new JsonConverter[]
67 {
68 // Analyze Re server only supports up to 3 sub-second decimal places.
69 new IsoDateTimeConverter {
70 DateTimeFormat = API.DateTimeFormat,
71 DateTimeStyles = DateTimeStyles.AdjustToUniversal
72 },
74 new StringEnumConverter(),
77 new UriConverter()
78 },
79 ContractResolver = new AnalyzeReSerializationContractResolver()
80 });
81
84 public readonly JsonSerializerSettings DeserializerSettings = DefaultDeserializerSettings.ShallowCopy();
85
88 public readonly JsonSerializerSettings SerializerSettings = DefaultSerializerSettings.ShallowCopy();
89 #endregion Serializer Settings
90
91 #region Interface Properties
93 public string ContentType { get; set; }
95 public CultureInfo Culture { get; set; }
97 public string DateFormat { get; set; }
99 public string Namespace { get; set; }
101 public string RootElement { get; set; }
102 #endregion Interface Properties
103
106 {
107 Culture = CultureInfo.InvariantCulture;
108 ContentType = "application/json";
109 }
110
119 T IDeserializer.Deserialize<T>(IRestResponse response)
120 {
121 return Deserialize<T>(response.Content);
122 }
123
132 public T Deserialize<T>(IRestResponse response)
133 {
134 return Deserialize<T>(response.Content);
135 }
136
145 public T Deserialize<T>(string json)
146 {
147 return JsonConvert.DeserializeObject<T>(json, DeserializerSettings);
148 }
149
159 public object Deserialize(string json, Type deserializeType)
160 {
161 return JsonConvert.DeserializeObject(json, deserializeType, DeserializerSettings);
162 }
163
167 public string Serialize(object obj)
168 {
169 return Serialize(obj, false);
170 }
171
176 public string Serialize(object obj, bool indented)
177 {
178 return JsonConvert.SerializeObject(obj,
179 indented ? Formatting.Indented : Formatting.None, SerializerSettings);
180 }
181 }
182}
RestSharp.Deserializers.IDeserializer IDeserializer
RestSharp.Serializers.ISerializer ISerializer
API methods / requests made available to the user.
static readonly string DateTimeFormat
The format used when transmitting DateTime information to Analyze Re servers.
A pre-configured RestSharp serializer / deserializer which is made to support parsing of AnalyzeRe AP...
string Serialize(object obj, bool indented)
Serialize the object as JSON.
static readonly AnalyzeReJsonConverter Default
Returns the default AnalyzeReJsonConverter instance.
string RootElement
RestSharp.Deserializers.IDeserializer.RootElement.
string Serialize(object obj)
Serialize the object as JSON.
string ContentType
RestSharp.Deserializers.IDeserializer.ContentType.
AnalyzeReJsonConverter()
Create a new AnalyzeRe JsonConverter.
static JsonSerializerSettings DefaultDeserializerSettings
The Newtonsoft.Json.JsonSerializerSettings settings used for deserializing resources.
string Namespace
RestSharp.Deserializers.IDeserializer.Namespace.
readonly JsonSerializerSettings DeserializerSettings
The JsonSerializerSettings settings used for deserializing resources.
CultureInfo Culture
RestSharp.Deserializers.IDeserializer.Culture.
static JsonSerializerSettings DefaultSerializerSettings
The Newtonsoft.Json.JsonSerializerSettings settings used for serializing resources.
readonly JsonSerializerSettings SerializerSettings
The JsonSerializerSettings settings used for serializing resources.
object Deserialize(string json, Type deserializeType)
Deserializes the rest response to a run-time type as per this converter's configuration.
string DateFormat
RestSharp.Deserializers.IDeserializer.DateFormat.
A custom property contract resolver which allows Server-Generated Analyze Re properties (ServerGenera...
Ensure that when converting arbitrary dictionaries, nested dictionaries are correctly converted as we...
Allows serializing and deserializing derived Analyze Re Resources to a target base type....
Allows serializing and deserializing derived AnalyzeRe Resource Views to a target base type....
Converts JSON string representations of Perspective to an instance.
Allows serializing and deserializing PortfolioViews, which require a special rule since they can only...
Deserializes AnalyzeRe API Reference objects to a new instance of a the target generic Reference type...
Properties tagged with the framework IgnoreDataMemberAttribute should be ignored by the serializers....
Converts JSON string representations of URLs to and from System.Uri instances.