Skip to content
This repository was archived by the owner on Jan 24, 2021. It is now read-only.

Commit 4a37969

Browse files
committed
removed binaryformatter replaced with json serializer
1 parent 2640f83 commit 4a37969

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/Nancy/DefaultObjectSerializer.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace Nancy
33
using System;
44
using System.IO;
55
using System.Runtime.Serialization;
6-
using System.Runtime.Serialization.Formatters.Binary;
6+
using Nancy.Json;
77

88
public class DefaultObjectSerializer : IObjectSerializer
99
{
@@ -16,14 +16,14 @@ public string Serialize(object sourceObject)
1616
{
1717
if (sourceObject == null)
1818
{
19-
return String.Empty;
19+
return string.Empty;
2020
}
2121

22-
var formatter = new BinaryFormatter();
23-
2422
using (var outputStream = new MemoryStream())
23+
using (var writer = new StreamWriter(outputStream))
2524
{
26-
formatter.Serialize(outputStream, sourceObject);
25+
var jsonSerializer = new JsonSerializer(new JavaScriptSerializer());
26+
jsonSerializer.Serialize(sourceObject, writer);
2727

2828
var outputBytes = outputStream.GetBuffer();
2929

@@ -47,11 +47,11 @@ public object Deserialize(string sourceString)
4747
{
4848
var inputBytes = Convert.FromBase64String(sourceString);
4949

50-
var formatter = new BinaryFormatter();
51-
5250
using (var inputStream = new MemoryStream(inputBytes, false))
51+
using (var streamreader = new StreamReader(inputStream))
5352
{
54-
return formatter.Deserialize(inputStream);
53+
var deserialzier = new JsonDeserializer(new JavaScriptSerializer());
54+
return deserialzier.Deserialize(streamreader);
5555
}
5656
}
5757
catch (FormatException)
@@ -62,10 +62,10 @@ public object Deserialize(string sourceString)
6262
{
6363
return null;
6464
}
65-
catch (IOException)
66-
{
67-
return null;
68-
}
65+
catch (IOException)
66+
{
67+
return null;
68+
}
6969
}
7070
}
7171
}

0 commit comments

Comments
 (0)