I have a class Foo and its FooConverter as defined below:
[JsonConverter(typeof(FooConverter))]
public class Foo
{
    public string Something { get; set; }
}
public class FooConverter : JsonConverter
{
    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
        writer.WriteValue(((Foo)value).Something);
    }
    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
        var str = reader.ReadAsString();
        if (str == null)
        {
            throw new JsonSerializationException();
        }    
        // return new Foo {Something = serializer.Deserialize<string>(reader)};
        return new Foo {Something = str};
    }
    public override bool CanConvert(Type objectType)
    {
        return objectType == typeof(Foo);
    }
}
Serializing works fine. But when deserializing:
var foo = JsonConvert.DeserializeObject<Foo>("\"something\"");
it throws JsonSerializationException because reader.ReadAsString is null.
But I don't understand why it has to be null... reader.ReadAsString works perfectly find if I'm doing it manually like so:
var reader = new JsonTextReader(new StringReader("\"something\""));
var str = reader.ReadAsString(); // str is now `something` NOT null
Although I can fix FooConverter by using serializer.Deserialize<string>(reader) in ReadJson, I still want to understand why reader.ReadAsString fails in FooConverter.ReadJson.
 
     
    