I am working on a kind of raw converter. When deserializing the decorated attribute, I need to get the raw string from the source.
public class X
{
[JsonConverter(typeof(MyConverter))]
public string Y {get;set;}
}
Y
will contain a serialized object, let's say {"a":1,"b":2}
. Thus from JSON point of view the property Y will contain an object {"Y":{"a":1,"b":2}}
. But I need it back as exactly the same string when deserializing.
This approach works, but takes a double load as it is deserialized and serialized back again, and it still can happen that it will be serialized in a different way.
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JObject jo = JObject.Load(reader);
return jo.ToString(serializer.Formatting, serializer.Converters.ToArray());
}
What I need is something that allows me to read as raw string from the beginning till the end of a JSON object. Unfortunately, the JsonReader
is a tokenizer, and it does the conversions right ahead while reading.