public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (objectType != typeof(PatchDocument)) { throw new ArgumentException("Object must be of type PatchDocument", nameof(objectType)); } try { if (reader.TokenType == JsonToken.Null) { return(null); } var patch = JArray.Load(reader); return(PatchDocument.Parse(patch.ToString())); } catch (Exception ex) { throw new ArgumentException("Invalid patch document: " + ex.Message); } }