annotate Implab.Test/JsonTests.cs @ 264:3a6e18c432be v3

Added XmlToJson xsl transformation. Added JsonXmlReader.CreateJsonXmlReader(...) methods Added SerializationHelpers.SerializeJson/DeserializeJson methods
author cin
date Mon, 16 Apr 2018 18:43:49 +0300
parents f1696cdc3d7a
children 74e048cbaac8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
262
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
1 using Xunit;
158
130781364799 refactoring, code cleanup
cin
parents:
diff changeset
2 using System;
183
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
3 using Implab.Automaton;
262
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
4 using Implab.Xml;
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
5 using System.Xml;
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
6 using Implab.Formats;
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
7 using Implab.Formats.Json;
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
8 using System.IO;
264
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
9 using Implab.Test.Model;
262
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
10
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
11 namespace Implab.Test {
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
12 public class JsonTests {
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
13
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
14 [Fact]
182
76e8f2ba12b8 pretty print DFA, the minimization is still buggy
cin
parents: 158
diff changeset
15 public void TestScannerValidTokens() {
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
16 using (var scanner = JsonStringScanner.Create(@"9123, -123, 0, 0.1, -0.2, -0.1e3, 1.3E-3, ""some \t\n\u0020 text"", literal []{}:")) {
183
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
17
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents: 184
diff changeset
18 Tuple<JsonTokenType, object>[] expexted = {
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
19 new Tuple<JsonTokenType,object>(JsonTokenType.Number, "9123"),
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
20 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
21 new Tuple<JsonTokenType,object>(JsonTokenType.Number, "-123"),
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
22 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
23 new Tuple<JsonTokenType,object>(JsonTokenType.Number, "0"),
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
24 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
25 new Tuple<JsonTokenType,object>(JsonTokenType.Number, "0.1"),
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
26 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
27 new Tuple<JsonTokenType,object>(JsonTokenType.Number, "-0.2"),
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
28 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
29 new Tuple<JsonTokenType,object>(JsonTokenType.Number, "-0.1e3"),
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
30 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
31 new Tuple<JsonTokenType,object>(JsonTokenType.Number, "1.3E-3"),
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
32 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
183
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
33 new Tuple<JsonTokenType,object>(JsonTokenType.String, "some \t\n text"),
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
34 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, null),
183
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
35 new Tuple<JsonTokenType,object>(JsonTokenType.Literal, "literal"),
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
36 new Tuple<JsonTokenType,object>(JsonTokenType.BeginArray, null),
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
37 new Tuple<JsonTokenType,object>(JsonTokenType.EndArray, null),
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
38 new Tuple<JsonTokenType,object>(JsonTokenType.BeginObject, null),
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
39 new Tuple<JsonTokenType,object>(JsonTokenType.EndObject, null),
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
40 new Tuple<JsonTokenType,object>(JsonTokenType.NameSeparator, null)
183
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
41 };
182
76e8f2ba12b8 pretty print DFA, the minimization is still buggy
cin
parents: 158
diff changeset
42
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
43 string value;
183
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
44 JsonTokenType tokenType;
262
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
45 for (var i = 0; i < expexted.Length; i++) {
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
46
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
47 Assert.True(scanner.ReadToken(out value, out tokenType));
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
48 Assert.Equal(expexted[i].Item1, tokenType);
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
49 Assert.Equal(expexted[i].Item2, value);
183
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
50 }
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
51
262
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
52 Assert.False(scanner.ReadToken(out value, out tokenType));
183
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
53 }
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
54 }
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
55
262
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
56 [Fact]
183
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
57 public void TestScannerBadTokens() {
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents: 184
diff changeset
58 var bad = new[] {
183
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
59 " 1",
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
60 " literal",
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
61 " \"",
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
62 "\"unclosed string",
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
63 "1.bad",
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
64 "001", // should be read as three numbers
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
65 "--10",
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
66 "+10",
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
67 "1.0.0",
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
68 "1e1.0",
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
69 "l1teral0",
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
70 ".123",
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
71 "-.123"
182
76e8f2ba12b8 pretty print DFA, the minimization is still buggy
cin
parents: 158
diff changeset
72 };
76e8f2ba12b8 pretty print DFA, the minimization is still buggy
cin
parents: 158
diff changeset
73
262
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
74 foreach (var json in bad) {
228
6fa235c5a760 Rewritten JsonScanner, JsonParser, fixed naming style
cin
parents: 227
diff changeset
75 using (var scanner = JsonStringScanner.Create(json)) {
183
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
76 try {
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents: 228
diff changeset
77 string value;
183
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
78 JsonTokenType token;
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
79 scanner.ReadToken(out value, out token);
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents: 184
diff changeset
80 if (!Object.Equals(value, json)) {
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents: 184
diff changeset
81 Console.WriteLine("'{0}' is read as {1}", json, value is String ? String.Format("'{0}'", value) : value);
183
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
82 continue;
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
83 }
262
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
84 Assert.True(false, $"Token '{json}' shouldn't pass");
183
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
85 } catch (ParserException e) {
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
86 Console.WriteLine(e.Message);
4f82e0f161c3 fixed DFA optimization, JSON is fully functional
cin
parents: 182
diff changeset
87 }
262
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
88 }
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents: 184
diff changeset
89 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents: 184
diff changeset
90 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents: 184
diff changeset
91
262
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
92 [Fact]
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
93 public void JsonXmlReaderSimpleTest() {
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
94 var json = "\"some text\"";
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
95 //Console.WriteLine($"JSON: {json}");
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
96 //Console.WriteLine("XML");
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
97 /*using (var xmlReader = new JsonXmlReader(new JSONParser(json), new JsonXmlReaderOptions { NamespaceUri = "JsonXmlReaderSimpleTest", RootName = "string", NodesPrefix = "json" })) {
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
98 Assert.AreEqual(xmlReader.ReadState, System.Xml.ReadState.Initial);
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
99
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
100 AssertRead(xmlReader, XmlNodeType.XmlDeclaration);
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
101 AssertRead(xmlReader, XmlNodeType.Element);
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
102 AssertRead(xmlReader, XmlNodeType.Text);
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
103 AssertRead(xmlReader, XmlNodeType.EndElement);
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
104 Assert.IsFalse(xmlReader.Read());
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
105 }*/
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
106
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
107 DumpJsonParse("\"text value\"");
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
108 DumpJsonParse("null");
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
109 DumpJsonParse("true");
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
110 DumpJsonParse("{}");
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
111 DumpJsonParse("[]");
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
112 DumpJsonParse("{\"one\":1, \"two\":2}");
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
113 DumpJsonParse("[1,\"\",2,3]");
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
114 DumpJsonParse("[{\"info\": [7,8,9]}]");
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
115 DumpJsonFlatParse("[1,2,\"\",[3,4],{\"info\": [5,6]},{\"num\": [7,8,null]}, null,[null]]");
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents: 184
diff changeset
116 }
236
302ca905c19e JsonReader optimizations
cin
parents: 229
diff changeset
117
264
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
118 [Fact]
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
119 public void XmlToJsonTransform() {
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
120 var person = new Person {
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
121 FirstName = "Charlie",
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
122 LastName = "Brown",
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
123 Age = 19,
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
124 AgeSpecified = true
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
125 };
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
126
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
127 var doc = SerializationHelpers.SerializeAsXmlDocument(person);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
128
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
129 using (var writer = new StringWriter()) {
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
130 XmlToJson.Default.Transform(doc,null, writer);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
131 Console.WriteLine(writer.ToString());
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
132 }
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
133 }
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
134
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
135 [Fact]
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
136 public void JsonSerialization() {
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
137 var person = new Person {
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
138 FirstName = "Charlie",
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
139 LastName = "Brown",
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
140 Age = 19,
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
141 AgeSpecified = true,
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
142 Tags = new [] { "brave", "stupid" }
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
143 };
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
144
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
145 var data = SerializationHelpers.SerializeJsonAsString(person);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
146 Console.WriteLine(data);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
147 var clone = SerializationHelpers.DeserializeJsonFromString<Person>(data);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
148
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
149 Assert.Equal(person.FirstName, clone.FirstName);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
150 Assert.Equal(person.LastName, clone.LastName);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
151 Assert.Equal(person.Age, clone.Age);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
152 Assert.Equal(person.AgeSpecified, clone.AgeSpecified);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
153 Assert.Equal(person.Tags, person.Tags);
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
154 }
3a6e18c432be Added XmlToJson xsl transformation.
cin
parents: 262
diff changeset
155
262
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
156 void AssertRead(XmlReader reader, XmlNodeType expected) {
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
157 Assert.True(reader.Read());
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
158 Console.WriteLine($"{new string(' ', reader.Depth * 2)}{reader}");
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
159 Assert.Equal(expected, reader.NodeType);
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents: 184
diff changeset
160 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents: 184
diff changeset
161
262
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
162 void DumpJsonParse(string json) {
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
163 Console.WriteLine($"JSON: {json}");
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
164 Console.WriteLine("XML");
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
165 using (var xmlWriter = XmlWriter.Create(Console.Out, new XmlWriterSettings {
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
166 Indent = true,
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
167 CloseOutput = false,
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
168 ConformanceLevel = ConformanceLevel.Document
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
169 }))
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
170 using (var xmlReader = new JsonXmlReader(JsonReader.ParseString(json), new JsonXmlReaderOptions { NamespaceUri = "JsonXmlReaderSimpleTest", NodesPrefix = "json" })) {
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
171 xmlWriter.WriteNode(xmlReader, false);
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
172 }
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
173 Console.WriteLine();
227
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents: 184
diff changeset
174 }
8d5de4eb9c2c Reimplemented JsonXmlReader, added support for null values: JSON null values are
cin
parents: 184
diff changeset
175
262
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
176 void DumpJsonFlatParse(string json) {
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
177 Console.WriteLine($"JSON: {json}");
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
178 Console.WriteLine("XML");
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
179 using (var xmlWriter = XmlWriter.Create(Console.Out, new XmlWriterSettings {
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
180 Indent = true,
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
181 CloseOutput = false,
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
182 ConformanceLevel = ConformanceLevel.Document
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
183 }))
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
184 using (var xmlReader = new JsonXmlReader(JsonReader.ParseString(json), new JsonXmlReaderOptions { NamespaceUri = "JsonXmlReaderSimpleTest", NodesPrefix = "", FlattenArrays = true })) {
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
185 xmlWriter.WriteNode(xmlReader, false);
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
186 }
f1696cdc3d7a Added IInitializable.Initialize() overload
cin
parents: 236
diff changeset
187 Console.WriteLine();
158
130781364799 refactoring, code cleanup
cin
parents:
diff changeset
188 }
130781364799 refactoring, code cleanup
cin
parents:
diff changeset
189 }
130781364799 refactoring, code cleanup
cin
parents:
diff changeset
190 }
130781364799 refactoring, code cleanup
cin
parents:
diff changeset
191