Open PeterN opened 10 years ago
@PeterN could you write some tests for it.
For those landing here with this need, you can try using this extension:
public class HandlesCharJsonSerializerStrategy : PocoJsonSerializerStrategy
{
protected override bool TrySerializeKnownTypes(object input, out object output)
{
// handle Char parameter
if (input is char)
{
output = input.ToString();
return true;
}
// else
return base.TrySerializeKnownTypes(input, out output);
}
}
You may also want to include this override, otherwise you'll get deserialization errors if a value is omitted:
public override object DeserializeObject(object value, Type type)
{
// handle empty Char
if (type == typeof(char) && string.IsNullOrEmpty(value as string)) value = "\0";
return base.DeserializeObject(value, type);
}
Treat a char field as a 1-character string. Deserializing to a char field already works fine.