mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 05:05:05 +00:00
feat: AbstractGenericJsonConverter exposes virtual methods for overriding object serialization/deserialization
This commit is contained in:
@@ -56,6 +56,17 @@ namespace ICD.Common.Utils.Json
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WriteObject(writer, value, serializer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Override to write the object value to the writer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="writer"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="serializer"></param>
|
||||||
|
protected virtual void WriteObject(JsonWriter writer, T value, JsonSerializer serializer)
|
||||||
|
{
|
||||||
writer.WriteStartObject();
|
writer.WriteStartObject();
|
||||||
{
|
{
|
||||||
WriteProperties(writer, value, serializer);
|
WriteProperties(writer, value, serializer);
|
||||||
@@ -119,6 +130,17 @@ namespace ICD.Common.Utils.Json
|
|||||||
if (reader.TokenType != JsonToken.StartObject)
|
if (reader.TokenType != JsonToken.StartObject)
|
||||||
throw new FormatException(string.Format("Expected {0} got {1}", JsonToken.StartObject, reader.TokenType));
|
throw new FormatException(string.Format("Expected {0} got {1}", JsonToken.StartObject, reader.TokenType));
|
||||||
|
|
||||||
|
return ReadObject(reader, serializer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Override to handle deserialization of the current StartObject token.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reader"></param>
|
||||||
|
/// <param name="serializer"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected virtual T ReadObject(JsonReader reader, JsonSerializer serializer)
|
||||||
|
{
|
||||||
T output = Instantiate();
|
T output = Instantiate();
|
||||||
|
|
||||||
reader.ReadObject(serializer, (p, r, s) => ReadProperty(p, r, output, s));
|
reader.ReadObject(serializer, (p, r, s) => ReadProperty(p, r, output, s));
|
||||||
|
|||||||
Reference in New Issue
Block a user