Skip to content

Commit

Permalink
-Added ItemIsReference, ItemReferenceLoopHandling, ItemTypeNameHandli…
Browse files Browse the repository at this point in the history
…ng, ItemConverterType to JsonPropertyAttribute
  • Loading branch information
JamesNK committed May 5, 2012
1 parent 0e22f39 commit 2dfd0bc
Show file tree
Hide file tree
Showing 14 changed files with 1,285 additions and 631 deletions.
29 changes: 29 additions & 0 deletions Src/Newtonsoft.Json.Tests/Converters/XmlNodeConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,35 @@ private XmlNode DeserializeXmlNode(string json, string deserializeRootElementNam
return node;
}

#if !NET20
[Test]
public void SerializeEmptyDocument()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<root />");

string json = JsonConvert.SerializeXmlNode(doc, Formatting.Indented, true);
Assert.AreEqual("null", json);

doc = new XmlDocument();
doc.LoadXml("<root></root>");

json = JsonConvert.SerializeXmlNode(doc, Formatting.Indented, true);
Assert.AreEqual("null", json);


XDocument doc1 = XDocument.Parse("<root />");

json = JsonConvert.SerializeXNode(doc1, Formatting.Indented, true);
Assert.AreEqual("null", json);

doc1 = XDocument.Parse("<root></root>");

json = JsonConvert.SerializeXNode(doc1, Formatting.Indented, true);
Assert.AreEqual("null", json);
}
#endif

[Test]
public void DocumentSerializeIndented()
{
Expand Down
34 changes: 17 additions & 17 deletions Src/Newtonsoft.Json.Tests/Linq/DynamicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -712,27 +712,27 @@ public void ImprovedDynamicLinqExample()
""StockValue"": 22050.0
}", json);
}
}

public class DynamicDictionary : DynamicObject
{
private readonly IDictionary<string, object> _values = new Dictionary<string, object>();
public class DynamicDictionary : DynamicObject
{
private readonly IDictionary<string, object> _values = new Dictionary<string, object>();

public override IEnumerable<string> GetDynamicMemberNames()
{
return _values.Keys;
}
public override IEnumerable<string> GetDynamicMemberNames()
{
return _values.Keys;
}

public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = _values[binder.Name];
return true;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = _values[binder.Name];
return true;
}

public override bool TrySetMember(SetMemberBinder binder, object value)
{
_values[binder.Name] = value;
return true;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
_values[binder.Name] = value;
return true;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.5.0.0")]
#if !PocketPC
[assembly: AssemblyFileVersion("4.5.4.14902")]
[assembly: AssemblyFileVersion("4.5.4.14905")]
#endif
27 changes: 27 additions & 0 deletions Src/Newtonsoft.Json.Tests/Schema/JsonSchemaGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,33 @@ public void JsonPropertyWithHandlingValues()
}
}", json);
}

[Test]
public void GenerateForNullableInt32()
{
JsonSchemaGenerator jsonSchemaGenerator = new JsonSchemaGenerator();

JsonSchema jsonSchema = jsonSchemaGenerator.Generate(typeof(NullableInt32TestClass));
string json = jsonSchema.ToString();

Assert.AreEqual(@"{
""type"": ""object"",
""properties"": {
""Value"": {
""required"": true,
""type"": [
""integer"",
""null""
]
}
}
}", json);
}
}

public class NullableInt32TestClass
{
public int? Value { get; set; }
}

public class DMDSLBase
Expand Down
Loading

0 comments on commit 2dfd0bc

Please sign in to comment.