Ejemplo n.º 1
0
        public static void SerializeToNode()
        {
            MyPoco   obj = MyPoco.Create();
            JsonNode dom = JsonSerializer.SerializeToNode(obj);

            JsonNode stringProp = dom["StringProp"];

            Assert.True(stringProp is JsonValue);
            Assert.Equal("Hello", stringProp.AsValue().GetValue <string>());

            JsonNode arrayProp = dom["IntArrayProp"];

            Assert.IsType <JsonArray>(arrayProp);
            Assert.Equal(1, arrayProp[0].AsValue().GetValue <int>());
            Assert.Equal(2, arrayProp[1].AsValue().GetValue <int>());
        }
Ejemplo n.º 2
0
        public static void SerializeToElement()
        {
            MyPoco      obj = MyPoco.Create();
            JsonElement dom = JsonSerializer.SerializeToElement(obj);

            JsonElement stringProp = dom.GetProperty("StringProp");

            Assert.Equal(JsonValueKind.String, stringProp.ValueKind);
            Assert.Equal("Hello", stringProp.ToString());

            JsonElement[] elements = dom.GetProperty("IntArrayProp").EnumerateArray().ToArray();
            Assert.Equal(JsonValueKind.Number, elements[0].ValueKind);
            Assert.Equal(1, elements[0].GetInt32());
            Assert.Equal(JsonValueKind.Number, elements[1].ValueKind);
            Assert.Equal(2, elements[1].GetInt32());
        }