Skip to content

Commit 36b4396

Browse files
committedNov 15, 2019
Add serializer configuration
1 parent 3d46ee1 commit 36b4396

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed
 

‎Utilities/Serializer.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,30 @@ namespace NFive.SDK.Core.Utilities
66
/// <summary>
77
/// Utilities to convert objects to and from JSON strings.
88
/// </summary>
9-
/// TODO: Convert to ISerializer interface and move Newtonsoft.Json requirement to higher level.
109
[PublicAPI]
1110
public class Serializer
1211
{
12+
/// <summary>Gets or sets the formatting option for the serializer.</summary>
13+
/// <value>The formatting option.</value>
14+
public Formatting Formatting { get; set; } = Formatting.None;
15+
16+
/// <summary>Gets or sets the settings for the serializer.</summary>
17+
/// <value>The serializer settings.</value>
18+
public JsonSerializerSettings Settings { get; set; }
19+
1320
/// <summary>
1421
/// Serializes the specified object to JSON.
1522
/// </summary>
1623
/// <param name="obj">The object to serialize.</param>
1724
/// <returns>The JSON representation of the object.</returns>
18-
public string Serialize(object obj) => JsonConvert.SerializeObject(obj);
25+
public string Serialize(object obj) => JsonConvert.SerializeObject(obj, this.Formatting, this.Settings);
1926

2027
/// <summary>
2128
/// Deserializes the specified JSON to a type.
2229
/// </summary>
2330
/// <typeparam name="T">The type to deserialize the JSON as.</typeparam>
2431
/// <param name="json">The JSON to deserialize.</param>
2532
/// <returns>The deserialized object.</returns>
26-
public T Deserialize<T>(string json) => JsonConvert.DeserializeObject<T>(json);
33+
public T Deserialize<T>(string json) => JsonConvert.DeserializeObject<T>(json, this.Settings);
2734
}
2835
}

0 commit comments

Comments
 (0)