Skip to content

Commit 86d9b9f

Browse files
scorteanucosminMrBlue
authored andcommitted
Update Serializer to not emit BOM
1 parent 3b45516 commit 86d9b9f

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/CompilerServices/Serializer.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,27 @@ namespace Oxide.CompilerServices;
99
public class Serializer : ISerializer
1010
{
1111
private readonly JsonSerializer _jsonSerializer;
12+
private readonly UTF8Encoding _encoding;
1213

1314
public Serializer()
1415
{
1516
_jsonSerializer = new JsonSerializer();
17+
_encoding = new UTF8Encoding(false);
1618
}
1719

1820
public byte[] Serialize<T>(T type) where T : class
1921
{
2022
using MemoryStream memoryStream = new();
21-
using StreamWriter writer = new(memoryStream, Encoding.UTF8);
22-
_jsonSerializer.Serialize(writer, type);
23-
writer.Flush();
23+
using StreamWriter streamWriter = new(memoryStream, _encoding);
24+
_jsonSerializer.Serialize(streamWriter, type);
25+
streamWriter.Flush();
2426
return memoryStream.ToArray();
2527
}
2628

2729
public T Deserialize<T>(byte[] data) where T : class
2830
{
2931
using MemoryStream memoryStream = new(data);
30-
using StreamReader reader = new(memoryStream, Encoding.UTF8);
31-
return (T)_jsonSerializer.Deserialize(reader, typeof(T));
32+
using StreamReader streamReader = new(memoryStream, _encoding);
33+
return (T)_jsonSerializer.Deserialize(streamReader, typeof(T));
3234
}
3335
}

0 commit comments

Comments
 (0)