I have to serialize/deserialize a non valid json containing javascript function like
{"Style":{"geometry":myFunction()}}
I m using a custom converter for my property
[JsonConverter(typeof(PlainJsonStringConverter))]
public string geometry { get; set; }
public class FunctionSerializer : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return (objectType == typeof(bool));
}
public override bool CanRead
{
get {
return true; }
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
Object result = null;
//TODO
return result;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
string valueAsString = Convert.ToString(value);
if (!string.IsNullOrWhiteSpace(valueAsString))
writer.WriteRawValue(valueAsString);
}
}
this work fine on serialization but on deserialization reader try to convert to boolean and throw an exception before calling my converter.