1515using System . Globalization ;
1616using System . IO ;
1717using System . Text ;
18- using System . Reflection ;
1918using ServiceStack . Text . Common ;
2019using ServiceStack . Text . Jsv ;
2120
@@ -26,7 +25,7 @@ namespace ServiceStack.Text
2625 /// </summary>
2726 public static class TypeSerializer
2827 {
29- private static readonly UTF8Encoding UTF8EncodingWithoutBom = new UTF8Encoding ( false ) ;
28+ public static UTF8Encoding UTF8Encoding = new UTF8Encoding ( false ) ; //Don't emit UTF8 BOM by default
3029
3130 public const string DoubleQuoteString = "\" \" " ;
3231
@@ -212,15 +211,15 @@ public static void SerializeToStream<T>(T value, Stream stream)
212211 }
213212 else
214213 {
215- var writer = new StreamWriter ( stream , UTF8EncodingWithoutBom ) ;
214+ var writer = new StreamWriter ( stream , UTF8Encoding ) ;
216215 JsvWriter < T > . WriteRootObject ( writer , value ) ;
217216 writer . Flush ( ) ;
218217 }
219218 }
220219
221220 public static void SerializeToStream ( object value , Type type , Stream stream )
222221 {
223- var writer = new StreamWriter ( stream , UTF8EncodingWithoutBom ) ;
222+ var writer = new StreamWriter ( stream , UTF8Encoding ) ;
224223 JsvWriter . GetWriteFn ( type ) ( writer , value ) ;
225224 writer . Flush ( ) ;
226225 }
@@ -234,15 +233,15 @@ public static T Clone<T>(T value)
234233
235234 public static T DeserializeFromStream < T > ( Stream stream )
236235 {
237- using ( var reader = new StreamReader ( stream , UTF8EncodingWithoutBom ) )
236+ using ( var reader = new StreamReader ( stream , UTF8Encoding ) )
238237 {
239238 return DeserializeFromString < T > ( reader . ReadToEnd ( ) ) ;
240239 }
241240 }
242241
243242 public static object DeserializeFromStream ( Type type , Stream stream )
244243 {
245- using ( var reader = new StreamReader ( stream , UTF8EncodingWithoutBom ) )
244+ using ( var reader = new StreamReader ( stream , UTF8Encoding ) )
246245 {
247246 return DeserializeFromString ( reader . ReadToEnd ( ) , type ) ;
248247 }
0 commit comments