-Fixed writing raw values twice with a trace writer
This commit is contained in:
@@ -76,6 +76,54 @@ Newtonsoft.Json Error: 0 : Error!
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void WriteJRaw()
|
||||
{
|
||||
ITraceWriter traceWriter = new MemoryTraceWriter();
|
||||
|
||||
JRaw settings = new JRaw("$('#element')");
|
||||
string json = JsonConvert.SerializeObject(settings, new JsonSerializerSettings
|
||||
{
|
||||
TraceWriter = traceWriter
|
||||
});
|
||||
|
||||
Assert.AreEqual("$('#element')", json);
|
||||
|
||||
Assert.IsTrue(traceWriter.ToString().EndsWith("Verbose Serialized JSON: " + Environment.NewLine + "$('#element')", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteJRawInArray()
|
||||
{
|
||||
ITraceWriter traceWriter = new MemoryTraceWriter();
|
||||
|
||||
List<JRaw> raws = new List<JRaw>
|
||||
{
|
||||
new JRaw("$('#element')"),
|
||||
new JRaw("$('#element')"),
|
||||
new JRaw("$('#element')")
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(raws, new JsonSerializerSettings
|
||||
{
|
||||
TraceWriter = traceWriter,
|
||||
Formatting = Formatting.Indented
|
||||
});
|
||||
|
||||
StringAssert.AreEqual(@"[
|
||||
$('#element'),
|
||||
$('#element'),
|
||||
$('#element')
|
||||
]", json);
|
||||
|
||||
Assert.IsTrue(traceWriter.ToString().EndsWith(@"Verbose Serialized JSON:
|
||||
[
|
||||
$('#element'),
|
||||
$('#element'),
|
||||
$('#element')
|
||||
]", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MemoryTraceWriterSerializeTest()
|
||||
{
|
||||
@@ -863,7 +911,7 @@ Newtonsoft.Json Error: 0 : Error!
|
||||
traceWriter.WriteValue(new Uri("http://www.google.com/"));
|
||||
traceWriter.WriteValue(Encoding.UTF8.GetBytes("String!"));
|
||||
traceWriter.WriteRawValue("[1],");
|
||||
traceWriter.WriteRaw("[1]");
|
||||
traceWriter.WriteRaw("[2]");
|
||||
traceWriter.WriteNull();
|
||||
traceWriter.WriteUndefined();
|
||||
traceWriter.WriteStartConstructor("ctor");
|
||||
@@ -919,7 +967,7 @@ Newtonsoft.Json Error: 0 : Error!
|
||||
""00000000-0000-0000-0000-000000000000"",
|
||||
""http://www.google.com/"",
|
||||
""U3RyaW5nIQ=="",
|
||||
[1],[1],[1],
|
||||
[1],[2],
|
||||
null,
|
||||
undefined,
|
||||
new ctor(
|
||||
|
||||
@@ -225,18 +225,6 @@ namespace Newtonsoft.Json.Serialization
|
||||
base.WriteWhitespace(ws);
|
||||
}
|
||||
|
||||
//protected override void WriteValueDelimiter()
|
||||
//{
|
||||
// _textWriter.WriteValueDelimiter();
|
||||
// _innerWriter.WriteValueDelimiter();
|
||||
// base.WriteValueDelimiter();
|
||||
//}
|
||||
|
||||
//protected override void WriteIndent()
|
||||
//{
|
||||
// base.WriteIndent();
|
||||
//}
|
||||
|
||||
public override void WriteComment(string text)
|
||||
{
|
||||
_textWriter.WriteComment(text);
|
||||
@@ -244,18 +232,6 @@ namespace Newtonsoft.Json.Serialization
|
||||
base.WriteComment(text);
|
||||
}
|
||||
|
||||
//public override void WriteEnd()
|
||||
//{
|
||||
// _textWriter.WriteEnd();
|
||||
// _innerWriter.WriteEnd();
|
||||
// base.WriteEnd();
|
||||
//}
|
||||
|
||||
//protected override void WriteEnd(JsonToken token)
|
||||
//{
|
||||
// base.WriteEnd(token);
|
||||
//}
|
||||
|
||||
public override void WriteStartArray()
|
||||
{
|
||||
_textWriter.WriteStartArray();
|
||||
@@ -314,6 +290,15 @@ namespace Newtonsoft.Json.Serialization
|
||||
base.WriteEndObject();
|
||||
}
|
||||
|
||||
public override void WriteRawValue(string json)
|
||||
{
|
||||
_textWriter.WriteRawValue(json);
|
||||
_innerWriter.WriteRawValue(json);
|
||||
|
||||
// calling base method will write json twice
|
||||
InternalWriteValue(JsonToken.Undefined);
|
||||
}
|
||||
|
||||
public override void WriteRaw(string json)
|
||||
{
|
||||
_textWriter.WriteRaw(json);
|
||||
@@ -321,20 +306,6 @@ namespace Newtonsoft.Json.Serialization
|
||||
base.WriteRaw(json);
|
||||
}
|
||||
|
||||
public override void WriteRawValue(string json)
|
||||
{
|
||||
_textWriter.WriteRawValue(json);
|
||||
_innerWriter.WriteRawValue(json);
|
||||
base.WriteRawValue(json);
|
||||
}
|
||||
|
||||
//protected override void WriteIndentSpace()
|
||||
//{
|
||||
// _textWriter.WriteIndentSpace();
|
||||
// _innerWriter.WriteIndentSpace();
|
||||
// base.WriteIndentSpace();
|
||||
//}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
_textWriter.Close();
|
||||
|
||||
Reference in New Issue
Block a user