public void Can_call_different_nested_types_custom_serializers() { JsConfig <InnerType> .SerializeFn = o => InnerType.Serialize(o); JsConfig <InnerType> .DeSerializeFn = str => InnerType.Deserialize(str); JsConfig <OuterType> .RawSerializeFn = d => JsonSerializer.SerializeToString(d.P1); JsConfig <OuterType> .RawDeserializeFn = str => { var d = str.FromJson <InnerType>(); return(new OuterType { P1 = d }); }; var t = new InnerType { A = "Hello", B = "World" }; var data = new OuterType { P1 = t }; var json = data.ToJson(); json.Print(); Assert.That(json, Is.EqualTo(@"""Hello-World""")); var outer = json.FromJson <OuterType>(); Assert.That(outer.P1.A, Is.EqualTo("Hello")); Assert.That(outer.P1.B, Is.EqualTo("World")); }
public void Can_call_different_nested_types_custom_serializers() { JsConfig<InnerType>.SerializeFn = o => InnerType.Serialize(o); JsConfig<InnerType>.DeSerializeFn = str => InnerType.Deserialize(str); JsConfig<OuterType>.RawSerializeFn = d => JsonSerializer.SerializeToString(d.P1); JsConfig<OuterType>.RawDeserializeFn = str => { var d = str.FromJson<InnerType>(); return new OuterType { P1 = d }; }; var t = new InnerType { A = "Hello", B = "World" }; var data = new OuterType { P1 = t }; var json = data.ToJson(); json.Print(); Assert.That(json, Is.EqualTo(@"""Hello-World""")); var outer = json.FromJson<OuterType>(); Assert.That(outer.P1.A, Is.EqualTo("Hello")); Assert.That(outer.P1.B, Is.EqualTo("World")); }