Say I have some video POCO with a description property which contains some text followed by tags in the form of [foo,bar]
. I would like to extract the tags from the description, remove it from the description and add the tags to the Tags
property.
I just want to custom deserialize the Description
property in a custom JsonConverter and let Json.Net deserialize the other properties as usual. I tried calling serializer.Deserialize<MyVideo>(reader)
but this will trigger my converter again, creating a recursive loop.
So is it possible to just handle the Description
and Tags
properties myself and let Json.Net deserialize everything else somehow?
Sample of the MyVideo POCO:
[JsonConverter(typeof(VideoDescriptionConverter))]
public class MyVideo
{
[JsonProperty("description")]
public string Description { get; set; }
public IList<string> Tags { get; set; }
// <more properties>
}
My VideoDescriptionConverter.ReadJson
method:
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
// This will recursively loop so doesn't work:
var video = serializer.Deserialize<MyVideo>(reader);
//video.Description = <extract description and tags>
//video.Tags = ...
return video;
}