diff options
author | Mitchell Hwang <mitchhwang1418@gmail.com> | 2020-02-19 22:11:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-19 22:11:07 +0300 |
commit | 30c1012ed59a2a07987d0f826eb50a506f5adc5d (patch) | |
tree | af9d7622767c8117aacf961ea26b56afd473fbf5 /mcs | |
parent | 45cb6fbba6a4bc0683aff5e0fd0968a8ade7c698 (diff) |
[bcl] Default XmlSerializer stream serialize to UTF8 Encoding (#18836)
* [mcs] Default XmlSerializer stream serialize to UTF8 Encoding
* [bcl] Add XmlSerialize Test to preserve UTF chars in stream
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs | 8 | ||||
-rw-r--r-- | mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs | 13 |
2 files changed, 15 insertions, 6 deletions
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs index 60bbc316699..7ef8b2ca554 100644 --- a/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs @@ -429,13 +429,9 @@ namespace System.Xml.Serialization } } - static Encoding DefaultEncoding = Encoding.Default; - public void Serialize (Stream stream, object o) { - XmlTextWriter xmlWriter = new XmlTextWriter (stream, DefaultEncoding); - xmlWriter.Formatting = Formatting.Indented; - Serialize (xmlWriter, o, null); + Serialize (stream, o, null); } public void Serialize (TextWriter textWriter, object o) @@ -452,7 +448,7 @@ namespace System.Xml.Serialization public void Serialize (Stream stream, object o, XmlSerializerNamespaces namespaces) { - XmlTextWriter xmlWriter = new XmlTextWriter (stream, DefaultEncoding); + XmlTextWriter xmlWriter = new XmlTextWriter (stream, Encoding.UTF8); xmlWriter.Formatting = Formatting.Indented; Serialize (xmlWriter, o, namespaces); } diff --git a/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs b/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs index 61835e709a0..e87df12964e 100644 --- a/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs +++ b/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs @@ -2676,6 +2676,19 @@ namespace MonoTests.System.XmlSerialization Assert.AreEqual ("<:GenComplexStructOfInt32String http://www.w3.org/2000/xmlns/:xsd='http://www.w3.org/2001/XMLSchema' http://www.w3.org/2000/xmlns/:xsi='http://www.w3.org/2001/XMLSchema-instance'><:something>123</><:simpleclass><:something>456</></><:simplestruct><:something>789</></><:listclass><:somelist><:int>100</><:int>200</></></><:arrayclass><:arr><:int>11</><:int>22</><:int>33</></></><:twoclass><:something1>10</><:something2>Ten</></><:derivedclass><:something1>two</><:something2>2</><:another1>1</><:another2>one</></><:derived2><:something1>4</><:something2>four</><:another1>3</><:another2>three</></><:nestedouter><:outer>5</></><:nestedinner><:inner>six</><:something>6</></></>", WriterText); } + [Test] + public void TestSerializeStreamPreserveUTFChars () { + string foo = "BÄR"; + XmlSerializer serializer = new XmlSerializer (typeof (string)); + + MemoryStream stream = new MemoryStream (); + + serializer.Serialize (stream, foo); + stream.Position = 0; + foo = (string) serializer.Deserialize (stream); + Assert.AreEqual("BÄR", foo); + } + [Test] // bug #80759 public void HasNullableField () { |