Let us say I have some data class
class MyData {
public string SomeValue;
}
And I have a JsonConverter
for this
class MyDataConverter : JsonConverter<MyData> {
public override void WriteJson(JsonWriter writer, MyData value,
JsonSerializer serializer)
{
writer.WriteValue(value.SomeValue);
}
public override MyData ReadJson(JsonReader reader, Type objectType,
MyData existingValue, bool hasExistingValue, JsonSerializer serializer)
{
var readerValue = (string) reader.Value;
return new MyData {SomeValue = readerValue};
}
}
Now I can use this converter on classes containing instances of MyData
. However, I can find no way to use this converter to convert instances of List<MyData>
, e.g.
class ClassIWantToSerialize
{
public List<MyData> SomeList;
}
Annotating [JsonConverter(typeof(MyDataConverter))]
did not work (not surprisingly).
What would be the easiest way to go about this?