-Modified project to support signed flag. Does not output InternalsVisibleTo attributes when present
-Improved error message on JObject and JArray Load method -Added WriteRawValue -Added missing XML documentation -Added SerializeObject overload that takes a formatting flag
This commit is contained in:
@@ -1308,19 +1308,19 @@ keyword such as type of business.""
|
||||
public void DefaultValueAttributeTest()
|
||||
{
|
||||
string json = JavaScriptConvert.SerializeObject(new DefaultValueAttributeTestClass(),
|
||||
new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
|
||||
Formatting.None, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
|
||||
Assert.AreEqual(@"{""TestField1"":0,""TestProperty1"":null}", json);
|
||||
|
||||
json = JavaScriptConvert.SerializeObject(new DefaultValueAttributeTestClass { TestField1 = int.MinValue, TestProperty1 = "NotDefault" },
|
||||
new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
|
||||
Formatting.None, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
|
||||
Assert.AreEqual(@"{""TestField1"":-2147483648,""TestProperty1"":""NotDefault""}", json);
|
||||
|
||||
json = JavaScriptConvert.SerializeObject(new DefaultValueAttributeTestClass { TestField1 = 21, TestProperty1 = "NotDefault" },
|
||||
new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
|
||||
Formatting.None, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
|
||||
Assert.AreEqual(@"{""TestProperty1"":""NotDefault""}", json);
|
||||
|
||||
json = JavaScriptConvert.SerializeObject(new DefaultValueAttributeTestClass { TestField1 = 21, TestProperty1 = "TestProperty1Value" },
|
||||
new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
|
||||
Formatting.None, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
|
||||
Assert.AreEqual(@"{}", json);
|
||||
}
|
||||
|
||||
|
||||
@@ -383,5 +383,32 @@ namespace Newtonsoft.Json.Tests
|
||||
|
||||
Assert.AreEqual("1", sw.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteRawValue()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringWriter sw = new StringWriter(sb);
|
||||
|
||||
using (JsonWriter jsonWriter = new JsonTextWriter(sw))
|
||||
{
|
||||
int i = 0;
|
||||
string rawJson = "[1,2]";
|
||||
|
||||
jsonWriter.WriteStartObject();
|
||||
|
||||
while (i < 3)
|
||||
{
|
||||
jsonWriter.WritePropertyName("d" + i);
|
||||
jsonWriter.WriteRawValue(rawJson);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
jsonWriter.WriteEndObject();
|
||||
}
|
||||
|
||||
Assert.AreEqual(@"{""d0"":[1,2],""d1"":[1,2],""d2"":[1,2]}", sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,5 +290,13 @@ Parameter name: index")]
|
||||
Assert.AreEqual(j, v4.Parent);
|
||||
Assert.AreEqual(1, j.IndexOf(v4));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(Exception), ExpectedMessage = "Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject")]
|
||||
public void Parse_ShouldThrowOnUnexpectedToken()
|
||||
{
|
||||
string json = @"{""prop"":""value""}";
|
||||
JArray.Parse(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -309,5 +309,13 @@ Parameter name: arrayIndex")]
|
||||
Assert.AreEqual("LastNameValue", raw.LastName);
|
||||
Assert.AreEqual("[1,2,3,4,5]", raw.RawContent.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(Exception), ExpectedMessage = "Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray")]
|
||||
public void Parse_ShouldThrowOnUnexpectedToken()
|
||||
{
|
||||
string json = @"[""prop""]";
|
||||
JObject.Parse(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>
|
||||
</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
||||
Reference in New Issue
Block a user