Can I make ServiceStack Deserialize json value of 1 as true?
Here’s a unit test showing what I want to do.
Is this possible? if so how?
public class Foo
{
public bool isWorking { get; set; }
}
…
[Test]
public void Deserialise1AsBoolean()
{
var json = @"{""isWorking"": 1}";
var myFoo = json.FromJson<Foo>();
Assert.IsTrue(myFoo.isWorking);
}
EDIT Here’s my solution, but please check out Mythz as well since I’m sure that will work also.
I deserialise to a custom struct
MyBoolrather thanbool.Here’s the code for the MyBool struct.
and change Foo to:
Criticisms welcome.