Skip to content

Commit 5b1688f

Browse files
committed
Replaced JSON.Net with DataContractJsonSerializer
1 parent fb67c00 commit 5b1688f

File tree

4 files changed

+38
-40
lines changed

4 files changed

+38
-40
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Collections.Generic;
2+
3+
namespace TestStack.BDDfy.Reporters.Diagnostics
4+
{
5+
public class DiagnosticsReport
6+
{
7+
public IList<StoryDiagnostic> Stories { get; set; }
8+
}
9+
}

src/TestStack.BDDfy/Reporters/Diagnostics/DiagnosticsReportBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public DiagnosticsReportBuilder(ISerializer serializer)
1818
public string CreateReport(FileReportModel model)
1919
{
2020
var graph = GetDiagnosticData(model);
21-
var rootObject = new { Stories = graph };
21+
var rootObject = new DiagnosticsReport { Stories = graph };
2222
return _serializer.Serialize(rootObject);
2323
}
2424

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
1+
using System.IO;
2+
using System.Runtime.Serialization.Json;
3+
using System.Text;
4+
15
namespace TestStack.BDDfy.Reporters.Serializers
26
{
3-
#if NET40
4-
using System.Web.Script.Serialization;
5-
67
public class JsonSerializer : ISerializer
78
{
89
public string Serialize(object obj)
910
{
10-
var serializer = new JavaScriptSerializer();
11-
string json = serializer.Serialize(obj);
11+
var serializer = new DataContractJsonSerializer(obj.GetType());
12+
string json;
13+
using (var stream = new MemoryStream())
14+
{
15+
serializer.WriteObject(stream, obj);
16+
json = Encoding.UTF8.GetString(stream.ToArray());
17+
}
1218

1319
return new JsonFormatter(json).Format();
1420
}
1521
}
16-
17-
#else
18-
using Newtonsoft.Json;
19-
20-
public class JsonSerializer : ISerializer
21-
{
22-
public string Serialize(object obj)
23-
{
24-
return JsonConvert.SerializeObject(obj, Formatting.Indented,
25-
new JsonSerializerSettings
26-
{
27-
NullValueHandling = NullValueHandling.Ignore,
28-
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
29-
});
30-
}
31-
}
32-
33-
#endif
34-
3522
}

src/TestStack.BDDfy/project.json

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@
77
"embed": "**/Scripts/*.*"
88
},
99
"dependencies": {
10-
"NETStandard.Library": "1.6.0",
11-
"Newtonsoft.Json": "9.0.1"
10+
"NETStandard.Library": "1.6.0"
1211
},
1312

1413
"frameworks": {
1514
"net40": {
1615
"dependencies": {
1716

1817
},
19-
"frameworkAssemblies": {
20-
"System.Web": "4.0.0.0",
21-
"System.Web.Extensions": "4.0.0.0"
22-
},
18+
"frameworkAssemblies": {
19+
"System.Runtime.Serialization": "4.0.0.0",
20+
"System.Xml": "4.0.0.0"
21+
},
2322
"buildOptions": {
2423
"define": [
2524
"APPDOMAIN",
@@ -29,15 +28,18 @@
2928
},
3029
"netstandard1.5": {
3130
"imports": "dnxcore50",
32-
"dependencies": {
33-
"System.Reflection.TypeExtensions": "4.1.0",
34-
"System.Runtime.Loader": "4.0.0",
35-
"System.Threading.ThreadPool": "4.0.10",
36-
"System.Linq.Expressions": "4.1.0",
37-
"System.Reflection": "4.1.0",
38-
"System.Runtime.Extensions": "4.1.0",
39-
"System.Diagnostics.StackTrace": "4.0.1"
40-
}
31+
"dependencies": {
32+
"System.Diagnostics.StackTrace": "4.0.1",
33+
"System.Linq.Expressions": "4.1.0",
34+
"System.Reflection": "4.1.0",
35+
"System.Reflection.TypeExtensions": "4.1.0",
36+
"System.Runtime.Extensions": "4.1.0",
37+
"System.Runtime.Loader": "4.0.0",
38+
"System.Runtime.Serialization.Json": "4.0.2",
39+
"System.Runtime.Serialization.Primitives": "4.1.1",
40+
"System.Text.Encoding": "4.0.11",
41+
"System.Threading.ThreadPool": "4.0.10"
42+
}
4143
}
4244
}
4345
}

0 commit comments

Comments
 (0)