-Change BSON writer to write new binary subtype

-Fix BSON reader to read the old binary subtype correctly
-Added JsonNet35BinaryCompadibility to BSON reader for incorrectly written BSON binary values
-Changed JSON schema to use required flags instead of optional as defined in JSON schema spec 3.0
-Changed JSON schema to use divisibleBy instead of maxDecimals as defined in JSON schema spec 3.0
-Fixed detection of serialization specified flag properties
-Updated to latest version of NuGet
This commit is contained in:
JamesNK
2010-12-19 00:29:41 +00:00
parent 2e7b8e5279
commit 5ccd826951
20 changed files with 194 additions and 80 deletions
@@ -72,6 +72,7 @@ namespace Newtonsoft.Json.Tests.Bson
byte[] data = MiscellaneousUtils.HexToBytes("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-02-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00"); byte[] data = MiscellaneousUtils.HexToBytes("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-02-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00");
MemoryStream ms = new MemoryStream(data); MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms); BsonReader reader = new BsonReader(ms);
reader.JsonNet35BinaryCompadibility = true;
reader.ReadRootValueAsArray = true; reader.ReadRootValueAsArray = true;
reader.DateTimeKindHandling = DateTimeKind.Utc; reader.DateTimeKindHandling = DateTimeKind.Utc;
@@ -250,6 +251,7 @@ namespace Newtonsoft.Json.Tests.Bson
MemoryStream ms = new MemoryStream(data); MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms, true, DateTimeKind.Utc); BsonReader reader = new BsonReader(ms, true, DateTimeKind.Utc);
reader.JsonNet35BinaryCompadibility = true;
Assert.AreEqual(true, reader.ReadRootValueAsArray); Assert.AreEqual(true, reader.ReadRootValueAsArray);
Assert.AreEqual(DateTimeKind.Utc, reader.DateTimeKindHandling); Assert.AreEqual(DateTimeKind.Utc, reader.DateTimeKindHandling);
@@ -378,11 +380,12 @@ namespace Newtonsoft.Json.Tests.Bson
[Test] [Test]
public void ReadNestedArrayIntoLinq() public void ReadNestedArrayIntoLinq()
{ {
string hexdoc = "87-00-00-00-05-5F-69-64-00-0C-00-00-00-02-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00"; string hexdoc = "87-00-00-00-05-5F-69-64-00-0C-00-00-00-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00";
byte[] data = MiscellaneousUtils.HexToBytes(hexdoc); byte[] data = MiscellaneousUtils.HexToBytes(hexdoc);
BsonReader reader = new BsonReader(new MemoryStream(data)); BsonReader reader = new BsonReader(new MemoryStream(data));
reader.JsonNet35BinaryCompadibility = true;
JObject o = (JObject)JToken.ReadFrom(reader); JObject o = (JObject)JToken.ReadFrom(reader);
Assert.AreEqual(3, o.Count); Assert.AreEqual(3, o.Count);
@@ -403,6 +406,7 @@ namespace Newtonsoft.Json.Tests.Bson
"82-00-00-00-07-5F-69-64-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00"); "82-00-00-00-07-5F-69-64-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00");
BsonReader reader1 = new BsonReader(new MemoryStream(data1)); BsonReader reader1 = new BsonReader(new MemoryStream(data1));
reader1.JsonNet35BinaryCompadibility = true;
// oid // oid
JObject o1 = (JObject)JToken.ReadFrom(reader1); JObject o1 = (JObject)JToken.ReadFrom(reader1);
@@ -411,6 +415,7 @@ namespace Newtonsoft.Json.Tests.Bson
"87-00-00-00-05-5F-69-64-00-0C-00-00-00-02-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00"); "87-00-00-00-05-5F-69-64-00-0C-00-00-00-02-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00");
BsonReader reader2 = new BsonReader(new MemoryStream(data2)); BsonReader reader2 = new BsonReader(new MemoryStream(data2));
reader2.JsonNet35BinaryCompadibility = true;
// bytes // bytes
JObject o2 = (JObject)JToken.ReadFrom(reader2); JObject o2 = (JObject)JToken.ReadFrom(reader2);
@@ -78,7 +78,7 @@ namespace Newtonsoft.Json.Tests.Bson
writer.WriteEnd(); writer.WriteEnd();
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
Assert.AreEqual("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-02-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00", bson); Assert.AreEqual("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-00-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00", bson);
} }
#endif #endif
@@ -120,10 +120,19 @@ namespace Newtonsoft.Json.Tests.Bson
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
string expected = "2B-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-05-32-00-0C-00-00-00-02-48-65-6C-6C-6F-20-77-6F-72-6C-64-21-00"; string expected = "2B-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-05-32-00-0C-00-00-00-00-48-65-6C-6C-6F-20-77-6F-72-6C-64-21-00";
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
Assert.AreEqual(expected, bson); Assert.AreEqual(expected, bson);
BsonReader reader = new BsonReader(new MemoryStream(ms.ToArray()));
reader.ReadRootValueAsArray = true;
reader.Read();
reader.Read();
reader.Read();
reader.Read();
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
Assert.AreEqual(data, reader.Value);
} }
[Test] [Test]
@@ -157,7 +166,7 @@ namespace Newtonsoft.Json.Tests.Bson
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
string expected = "87-00-00-00-05-5F-69-64-00-0C-00-00-00-02-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00"; string expected = "87-00-00-00-05-5F-69-64-00-0C-00-00-00-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00";
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
Assert.AreEqual(expected, bson); Assert.AreEqual(expected, bson);
@@ -470,7 +470,7 @@ namespace Newtonsoft.Json.Tests
""type"":""array"", ""type"":""array"",
""items"":{ ""items"":{
""type"":""number"", ""type"":""number"",
""maxDecimal"":2 ""divisibleBy"":0.1
} }
}"; }";
@@ -494,7 +494,7 @@ namespace Newtonsoft.Json.Tests
Assert.IsTrue(reader.Read()); Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Float, reader.TokenType); Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(@"Float 4.001 exceeds the maximum allowed number decimal places of 2. Line 1, position 15.", validationEventArgs.Message); Assert.AreEqual(@"Float 4.001 is not evenly divisible by 0.1. Line 1, position 15.", validationEventArgs.Message);
Assert.IsTrue(reader.Read()); Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType); Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
@@ -700,7 +700,7 @@ namespace Newtonsoft.Json.Tests
} }
[Test] [Test]
public void MissingNonoptionalProperties() public void MissingRequiredProperties()
{ {
string schemaJson = @"{ string schemaJson = @"{
""description"":""A person"", ""description"":""A person"",
@@ -708,8 +708,8 @@ namespace Newtonsoft.Json.Tests
""properties"": ""properties"":
{ {
""name"":{""type"":""string""}, ""name"":{""type"":""string""},
""hobbies"":{""type"":""string""}, ""hobbies"":{""type"":""string"",""required"":true},
""age"":{""type"":""integer""} ""age"":{""type"":""integer"",""required"":true}
} }
}"; }";
@@ -735,22 +735,22 @@ namespace Newtonsoft.Json.Tests
Assert.IsTrue(reader.Read()); Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndObject, reader.TokenType); Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
Assert.AreEqual("Non-optional properties are missing from object: hobbies, age. Line 1, position 16.", validationEventArgs.Message); Assert.AreEqual("Required properties are missing from object: hobbies, age. Line 1, position 16.", validationEventArgs.Message);
Assert.IsNotNull(validationEventArgs); Assert.IsNotNull(validationEventArgs);
} }
[Test] [Test]
public void MissingOptionalProperties() public void MissingNonRequiredProperties()
{ {
string schemaJson = @"{ string schemaJson = @"{
""description"":""A person"", ""description"":""A person"",
""type"":""object"", ""type"":""object"",
""properties"": ""properties"":
{ {
""name"":{""type"":""string""}, ""name"":{""type"":""string"",""required"":true},
""hobbies"":{""type"":""string"",optional:true}, ""hobbies"":{""type"":""string"",""required"":false},
""age"":{""type"":""integer"",optional:true} ""age"":{""type"":""integer""}
} }
}"; }";
@@ -873,7 +873,7 @@ namespace Newtonsoft.Json.Tests
""type"":""object"", ""type"":""object"",
""properties"": ""properties"":
{ {
""firstproperty"":{""type"":""string""} ""firstproperty"":{""type"":""string"",""required"":true}
}, },
""additionalProperties"":{} ""additionalProperties"":{}
}"; }";
@@ -884,7 +884,7 @@ namespace Newtonsoft.Json.Tests
""extends"":{""$ref"":""first""}, ""extends"":{""$ref"":""first""},
""properties"": ""properties"":
{ {
""secondproperty"":{""type"":""string""} ""secondproperty"":{""type"":""string"",""required"":true}
}, },
""additionalProperties"":false ""additionalProperties"":false
}"; }";
@@ -955,7 +955,7 @@ namespace Newtonsoft.Json.Tests
} }
[Test] [Test]
public void ExtendsMissingNonoptionalProperties() public void ExtendsMissingRequiredProperties()
{ {
string json = "{}"; string json = "{}";
@@ -972,7 +972,7 @@ namespace Newtonsoft.Json.Tests
Assert.AreEqual(JsonToken.EndObject, reader.TokenType); Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
Assert.AreEqual(1, errors.Count); Assert.AreEqual(1, errors.Count);
Assert.AreEqual("Non-optional properties are missing from object: secondproperty, firstproperty. Line 1, position 2.", errors[0]); Assert.AreEqual("Required properties are missing from object: secondproperty, firstproperty. Line 1, position 2.", errors[0]);
} }
[Test] [Test]
@@ -89,13 +89,13 @@ namespace Newtonsoft.Json.Tests.Schema
[Test] [Test]
public void ValidateFailureWithOutLineInfoBecauseOfEndToken() public void ValidateFailureWithOutLineInfoBecauseOfEndToken()
{ {
JsonSchema schema = JsonSchema.Parse("{'properties':{'lol':{}}}"); JsonSchema schema = JsonSchema.Parse("{'properties':{'lol':{'required':true}}}");
JObject o = JObject.Parse("{}"); JObject o = JObject.Parse("{}");
List<string> errors = new List<string>(); List<string> errors = new List<string>();
o.Validate(schema, (sender, args) => errors.Add(args.Message)); o.Validate(schema, (sender, args) => errors.Add(args.Message));
Assert.AreEqual("Non-optional properties are missing from object: lol.", errors[0]); Assert.AreEqual("Required properties are missing from object: lol.", errors[0]);
Assert.AreEqual(1, errors.Count); Assert.AreEqual(1, errors.Count);
} }
@@ -116,18 +116,18 @@ namespace Newtonsoft.Json.Tests.Schema
} }
[Test] [Test]
public void Optional() public void Required()
{ {
string json = @"{ string json = @"{
""description"":""Optional"", ""description"":""Required"",
""optional"":true ""required"":true
}"; }";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver()); JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json))); JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Optional", schema.Description); Assert.AreEqual("Required", schema.Description);
Assert.AreEqual(true, schema.Optional); Assert.AreEqual(true, schema.Required);
} }
[Test] [Test]
@@ -279,7 +279,7 @@ namespace Newtonsoft.Json.Tests.Schema
""maxItems"":2, ""maxItems"":2,
""minLength"":5, ""minLength"":5,
""maxLength"":50, ""maxLength"":50,
""maxDecimal"":3, ""divisibleBy"":3,
}"; }";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver()); JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
@@ -292,7 +292,7 @@ namespace Newtonsoft.Json.Tests.Schema
Assert.AreEqual(2, schema.MaximumItems); Assert.AreEqual(2, schema.MaximumItems);
Assert.AreEqual(5, schema.MinimumLength); Assert.AreEqual(5, schema.MinimumLength);
Assert.AreEqual(50, schema.MaximumLength); Assert.AreEqual(50, schema.MaximumLength);
Assert.AreEqual(3, schema.MaximumDecimals); Assert.AreEqual(3, schema.DivisibleBy);
} }
[Test] [Test]
@@ -94,10 +94,12 @@ namespace Newtonsoft.Json.Tests.Schema
""additionalProperties"": false, ""additionalProperties"": false,
""properties"": { ""properties"": {
""TestField1"": { ""TestField1"": {
""required"": true,
""type"": ""integer"", ""type"": ""integer"",
""default"": 21 ""default"": 21
}, },
""TestProperty1"": { ""TestProperty1"": {
""required"": true,
""type"": [ ""type"": [
""string"", ""string"",
""null"" ""null""
@@ -124,15 +126,18 @@ namespace Newtonsoft.Json.Tests.Schema
""type"": ""object"", ""type"": ""object"",
""properties"": { ""properties"": {
""Name"": { ""Name"": {
""required"": true,
""type"": [ ""type"": [
""string"", ""string"",
""null"" ""null""
] ]
}, },
""BirthDate"": { ""BirthDate"": {
""required"": true,
""type"": ""string"" ""type"": ""string""
}, },
""LastModified"": { ""LastModified"": {
""required"": true,
""type"": ""string"" ""type"": ""string""
} }
} }
@@ -151,36 +156,43 @@ namespace Newtonsoft.Json.Tests.Schema
""type"": ""object"", ""type"": ""object"",
""properties"": { ""properties"": {
""Id"": { ""Id"": {
""required"": true,
""type"": ""string"" ""type"": ""string""
}, },
""FName"": { ""FName"": {
""required"": true,
""type"": [ ""type"": [
""string"", ""string"",
""null"" ""null""
] ]
}, },
""LName"": { ""LName"": {
""required"": true,
""type"": [ ""type"": [
""string"", ""string"",
""null"" ""null""
] ]
}, },
""RoleId"": { ""RoleId"": {
""required"": true,
""type"": ""integer"" ""type"": ""integer""
}, },
""NullableRoleId"": { ""NullableRoleId"": {
""required"": true,
""type"": [ ""type"": [
""integer"", ""integer"",
""null"" ""null""
] ]
}, },
""NullRoleId"": { ""NullRoleId"": {
""required"": true,
""type"": [ ""type"": [
""integer"", ""integer"",
""null"" ""null""
] ]
}, },
""Active"": { ""Active"": {
""required"": true,
""type"": [ ""type"": [
""boolean"", ""boolean"",
""null"" ""null""
@@ -370,6 +382,7 @@ namespace Newtonsoft.Json.Tests.Schema
Assert.AreEqual(@"{ Assert.AreEqual(@"{
""id"": ""System.IO.DirectoryInfo"", ""id"": ""System.IO.DirectoryInfo"",
""required"": true,
""type"": [ ""type"": [
""object"", ""object"",
""null"" ""null""
@@ -377,6 +390,7 @@ namespace Newtonsoft.Json.Tests.Schema
""additionalProperties"": false, ""additionalProperties"": false,
""properties"": { ""properties"": {
""Name"": { ""Name"": {
""required"": true,
""type"": [ ""type"": [
""string"", ""string"",
""null"" ""null""
@@ -386,39 +400,49 @@ namespace Newtonsoft.Json.Tests.Schema
""$ref"": ""System.IO.DirectoryInfo"" ""$ref"": ""System.IO.DirectoryInfo""
}, },
""Exists"": { ""Exists"": {
""required"": true,
""type"": ""boolean"" ""type"": ""boolean""
}, },
""FullName"": { ""FullName"": {
""required"": true,
""type"": [ ""type"": [
""string"", ""string"",
""null"" ""null""
] ]
}, },
""Extension"": { ""Extension"": {
""required"": true,
""type"": [ ""type"": [
""string"", ""string"",
""null"" ""null""
] ]
}, },
""CreationTime"": { ""CreationTime"": {
""required"": true,
""type"": ""string"" ""type"": ""string""
}, },
""CreationTimeUtc"": { ""CreationTimeUtc"": {
""required"": true,
""type"": ""string"" ""type"": ""string""
}, },
""LastAccessTime"": { ""LastAccessTime"": {
""required"": true,
""type"": ""string"" ""type"": ""string""
}, },
""LastAccessTimeUtc"": { ""LastAccessTimeUtc"": {
""required"": true,
""type"": ""string"" ""type"": ""string""
}, },
""LastWriteTime"": { ""LastWriteTime"": {
""required"": true,
""type"": ""string"" ""type"": ""string""
}, },
""LastWriteTimeUtc"": { ""LastWriteTimeUtc"": {
""required"": true,
""type"": ""string"" ""type"": ""string""
}, },
""Attributes"": { ""Attributes"": {
""required"": true,
""type"": ""integer"" ""type"": ""integer""
} }
} }
@@ -458,21 +482,27 @@ namespace Newtonsoft.Json.Tests.Schema
""additionalProperties"": false, ""additionalProperties"": false,
""properties"": { ""properties"": {
""major"": { ""major"": {
""required"": true,
""type"": ""integer"" ""type"": ""integer""
}, },
""minor"": { ""minor"": {
""required"": true,
""type"": ""integer"" ""type"": ""integer""
}, },
""build"": { ""build"": {
""required"": true,
""type"": ""integer"" ""type"": ""integer""
}, },
""revision"": { ""revision"": {
""required"": true,
""type"": ""integer"" ""type"": ""integer""
}, },
""majorRevision"": { ""majorRevision"": {
""required"": true,
""type"": ""integer"" ""type"": ""integer""
}, },
""minorRevision"": { ""minorRevision"": {
""required"": true,
""type"": ""integer"" ""type"": ""integer""
} }
} }
@@ -503,6 +533,7 @@ namespace Newtonsoft.Json.Tests.Schema
""type"": ""object"", ""type"": ""object"",
""properties"": { ""properties"": {
""x"": { ""x"": {
""required"": true,
""type"": ""integer"", ""type"": ""integer"",
""enum"": [ ""enum"": [
0, 0,
@@ -552,13 +583,13 @@ namespace Newtonsoft.Json.Tests.Schema
Assert.AreEqual(@"{ Assert.AreEqual(@"{
""id"": ""Newtonsoft.Json.Tests.TestObjects.CircularReferenceClass"", ""id"": ""Newtonsoft.Json.Tests.TestObjects.CircularReferenceClass"",
""optional"": true,
""type"": [ ""type"": [
""object"", ""object"",
""null"" ""null""
], ],
""properties"": { ""properties"": {
""Name"": { ""Name"": {
""required"": true,
""type"": ""string"" ""type"": ""string""
}, },
""Child"": { ""Child"": {
@@ -579,13 +610,13 @@ namespace Newtonsoft.Json.Tests.Schema
Assert.AreEqual(@"{ Assert.AreEqual(@"{
""id"": ""Newtonsoft.Json.Tests.TestObjects.JsonPropertyWithHandlingValues"", ""id"": ""Newtonsoft.Json.Tests.TestObjects.JsonPropertyWithHandlingValues"",
""required"": true,
""type"": [ ""type"": [
""object"", ""object"",
""null"" ""null""
], ],
""properties"": { ""properties"": {
""DefaultValueHandlingIgnoreProperty"": { ""DefaultValueHandlingIgnoreProperty"": {
""optional"": true,
""type"": [ ""type"": [
""string"", ""string"",
""null"" ""null""
@@ -593,6 +624,7 @@ namespace Newtonsoft.Json.Tests.Schema
""default"": ""Default!"" ""default"": ""Default!""
}, },
""DefaultValueHandlingIncludeProperty"": { ""DefaultValueHandlingIncludeProperty"": {
""required"": true,
""type"": [ ""type"": [
""string"", ""string"",
""null"" ""null""
@@ -600,13 +632,13 @@ namespace Newtonsoft.Json.Tests.Schema
""default"": ""Default!"" ""default"": ""Default!""
}, },
""NullValueHandlingIgnoreProperty"": { ""NullValueHandlingIgnoreProperty"": {
""optional"": true,
""type"": [ ""type"": [
""string"", ""string"",
""null"" ""null""
] ]
}, },
""NullValueHandlingIncludeProperty"": { ""NullValueHandlingIncludeProperty"": {
""required"": true,
""type"": [ ""type"": [
""string"", ""string"",
""null"" ""null""
@@ -139,7 +139,7 @@ namespace Newtonsoft.Json.Tests.Schema
} }
[Test] [Test]
public void Optional() public void Required()
{ {
string schemaJson = @"{ string schemaJson = @"{
""description"":""A person"", ""description"":""A person"",
@@ -147,8 +147,8 @@ namespace Newtonsoft.Json.Tests.Schema
""properties"": ""properties"":
{ {
""name"":{""type"":""string""}, ""name"":{""type"":""string""},
""hobbies"":{""type"":""string"",optional:true}, ""hobbies"":{""type"":""string"",required:true},
""age"":{""type"":""integer"",optional:true} ""age"":{""type"":""integer"",required:true}
} }
}"; }";
@@ -158,9 +158,9 @@ namespace Newtonsoft.Json.Tests.Schema
Assert.AreEqual(JsonSchemaType.Object, model.Type); Assert.AreEqual(JsonSchemaType.Object, model.Type);
Assert.AreEqual(3, model.Properties.Count); Assert.AreEqual(3, model.Properties.Count);
Assert.AreEqual(false, model.Properties["name"].Optional); Assert.AreEqual(false, model.Properties["name"].Required);
Assert.AreEqual(true, model.Properties["hobbies"].Optional); Assert.AreEqual(true, model.Properties["hobbies"].Required);
Assert.AreEqual(true, model.Properties["age"].Optional); Assert.AreEqual(true, model.Properties["age"].Required);
} }
} }
} }
@@ -3385,6 +3385,7 @@ keyword such as type of business.""
public string Name { get; set; } public string Name { get; set; }
public int Age { get; set; } public int Age { get; set; }
public int Weight { get; set; } public int Weight { get; set; }
public int Height { get; set; }
// dummy. should never be used because it isn't of type bool // dummy. should never be used because it isn't of type bool
[JsonIgnore] [JsonIgnore]
@@ -3399,6 +3400,10 @@ keyword such as type of business.""
[JsonIgnore] [JsonIgnore]
public bool WeightSpecified; public bool WeightSpecified;
[JsonIgnore]
[System.Xml.Serialization.XmlIgnoreAttribute]
public bool HeightSpecified;
} }
[Test] [Test]
@@ -3419,28 +3424,36 @@ keyword such as type of business.""
Assert.IsNull(deserialized.Name); Assert.IsNull(deserialized.Name);
Assert.IsFalse(deserialized.NameSpecified); Assert.IsFalse(deserialized.NameSpecified);
Assert.IsFalse(deserialized.WeightSpecified); Assert.IsFalse(deserialized.WeightSpecified);
Assert.IsFalse(deserialized.HeightSpecified);
Assert.AreEqual(27, deserialized.Age); Assert.AreEqual(27, deserialized.Age);
c.NameSpecified = true; c.NameSpecified = true;
c.WeightSpecified = true; c.WeightSpecified = true;
c.HeightSpecified = true;
json = JsonConvert.SerializeObject(c, Formatting.Indented); json = JsonConvert.SerializeObject(c, Formatting.Indented);
Assert.AreEqual(@"{ Assert.AreEqual(@"{
""Name"": ""James"", ""Name"": ""James"",
""Age"": 27, ""Age"": 27,
""Weight"": 0 ""Weight"": 0,
""Height"": 0
}", json); }", json);
deserialized = JsonConvert.DeserializeObject<SpecifiedTestClass>(json); deserialized = JsonConvert.DeserializeObject<SpecifiedTestClass>(json);
Assert.AreEqual("James", deserialized.Name); Assert.AreEqual("James", deserialized.Name);
Assert.IsTrue(deserialized.NameSpecified); Assert.IsTrue(deserialized.NameSpecified);
Assert.IsTrue(deserialized.WeightSpecified); Assert.IsTrue(deserialized.WeightSpecified);
Assert.IsTrue(deserialized.HeightSpecified);
Assert.AreEqual(27, deserialized.Age); Assert.AreEqual(27, deserialized.Age);
}
// [Test]
// public void XmlSerializerSpecifiedTrueTest()
// {
// XmlSerializer s = new XmlSerializer(typeof(OptionalOrder)); // XmlSerializer s = new XmlSerializer(typeof(OptionalOrder));
// StringWriter sw = new StringWriter(); // StringWriter sw = new StringWriter();
// s.Serialize(sw, new OptionalOrder() { FirstOrder = "First", FirstOrderSpecified = true}); // s.Serialize(sw, new OptionalOrder() { FirstOrder = "First", FirstOrderSpecified = true });
// Console.WriteLine(sw.ToString()); // Console.WriteLine(sw.ToString());
@@ -3452,18 +3465,38 @@ keyword such as type of business.""
// OptionalOrder o = (OptionalOrder)s.Deserialize(new StringReader(xml)); // OptionalOrder o = (OptionalOrder)s.Deserialize(new StringReader(xml));
// Console.WriteLine(o.FirstOrder); // Console.WriteLine(o.FirstOrder);
// Console.WriteLine(o.FirstOrderSpecified); // Console.WriteLine(o.FirstOrderSpecified);
} // }
//public class OptionalOrder // [Test]
//{ // public void XmlSerializerSpecifiedFalseTest()
// // This field shouldn't be serialized // {
// // if it is uninitialized. // XmlSerializer s = new XmlSerializer(typeof(OptionalOrder));
// public string FirstOrder;
// // Use the XmlIgnoreAttribute to ignore the // StringWriter sw = new StringWriter();
// // special field named "FirstOrderSpecified". // s.Serialize(sw, new OptionalOrder() { FirstOrder = "First", FirstOrderSpecified = false });
// [System.Xml.Serialization.XmlIgnoreAttribute]
// public bool FirstOrderSpecified; // Console.WriteLine(sw.ToString());
//}
//// string xml = @"<?xml version=""1.0"" encoding=""utf-16""?>
////<OptionalOrder xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
//// <FirstOrder>First</FirstOrder>
////</OptionalOrder>";
//// OptionalOrder o = (OptionalOrder)s.Deserialize(new StringReader(xml));
//// Console.WriteLine(o.FirstOrder);
//// Console.WriteLine(o.FirstOrderSpecified);
// }
public class OptionalOrder
{
// This field shouldn't be serialized
// if it is uninitialized.
public string FirstOrder;
// Use the XmlIgnoreAttribute to ignore the
// special field named "FirstOrderSpecified".
[System.Xml.Serialization.XmlIgnoreAttribute]
public bool FirstOrderSpecified;
}
public class FamilyDetails public class FamilyDetails
{ {
@@ -23,11 +23,15 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
#endregion #endregion
using System;
namespace Newtonsoft.Json.Bson namespace Newtonsoft.Json.Bson
{ {
internal enum BsonBinaryType : byte internal enum BsonBinaryType : byte
{ {
Binary = 0x00,
Function = 0x01, Function = 0x01,
[Obsolete("This type has been deprecated in the BSON specification. Use Binary instead.")]
Data = 0x02, Data = 0x02,
Uuid = 0x03, Uuid = 0x03,
Md5 = 0x05, Md5 = 0x05,
+1 -1
View File
@@ -134,7 +134,7 @@ namespace Newtonsoft.Json.Bson
byte[] data = (byte[])value.Value; byte[] data = (byte[])value.Value;
_writer.Write(data.Length); _writer.Write(data.Length);
_writer.Write((byte)BsonBinaryType.Data); _writer.Write((byte)BsonBinaryType.Binary);
_writer.Write(data); _writer.Write(data);
} }
break; break;
+22 -2
View File
@@ -55,6 +55,7 @@ namespace Newtonsoft.Json.Bson
private ContainerContext _currentContext; private ContainerContext _currentContext;
private bool _readRootValueAsArray; private bool _readRootValueAsArray;
private bool _jsonNet35BinaryCompadibility;
private DateTimeKind _dateTimeKindHandling; private DateTimeKind _dateTimeKindHandling;
private enum BsonReaderState private enum BsonReaderState
@@ -82,6 +83,18 @@ namespace Newtonsoft.Json.Bson
} }
} }
/// <summary>
/// Gets or sets a value indicating whether binary data reading should compatible with incorrect Json.NET 3.5 written binary.
/// </summary>
/// <value>
/// <c>true</c> if binary data reading will be compatible with incorrect Json.NET 3.5 written binary; otherwise, <c>false</c>.
/// </value>
public bool JsonNet35BinaryCompadibility
{
get { return _jsonNet35BinaryCompadibility; }
set { _jsonNet35BinaryCompadibility = value; }
}
/// <summary> /// <summary>
/// Gets or sets a value indicating whether the root object will be read as a JSON array. /// Gets or sets a value indicating whether the root object will be read as a JSON array.
/// </summary> /// </summary>
@@ -526,8 +539,15 @@ namespace Newtonsoft.Json.Bson
{ {
int dataLength = ReadInt32(); int dataLength = ReadInt32();
// BsonBinaryType not used BsonBinaryType binaryType = (BsonBinaryType)ReadByte();
ReadByte();
#pragma warning disable 612,618
// the old binary type has the data length repeated in the data for some reason
if (binaryType == BsonBinaryType.Data && !_jsonNet35BinaryCompadibility)
{
dataLength = ReadInt32();
}
#pragma warning restore 612,618
return ReadBytes(dataLength); return ReadBytes(dataLength);
} }
+11 -4
View File
@@ -77,7 +77,7 @@ namespace Newtonsoft.Json
private IEnumerable<string> GetRequiredProperties(JsonSchemaModel schema) private IEnumerable<string> GetRequiredProperties(JsonSchemaModel schema)
{ {
return schema.Properties.Where(p => !p.Value.Optional).Select(p => p.Key); return schema.Properties.Where(p => p.Value.Required).Select(p => p.Key);
} }
} }
@@ -448,7 +448,7 @@ namespace Newtonsoft.Json
requiredProperties.Where(kv => !kv.Value).Select(kv => kv.Key).ToList(); requiredProperties.Where(kv => !kv.Value).Select(kv => kv.Key).ToList();
if (unmatchedRequiredProperties.Count > 0) if (unmatchedRequiredProperties.Count > 0)
RaiseError("Non-optional properties are missing from object: {0}.".FormatWith(CultureInfo.InvariantCulture, string.Join(", ", unmatchedRequiredProperties.ToArray())), schema); RaiseError("Required properties are missing from object: {0}.".FormatWith(CultureInfo.InvariantCulture, string.Join(", ", unmatchedRequiredProperties.ToArray())), schema);
} }
} }
@@ -564,8 +564,15 @@ namespace Newtonsoft.Json
if (schema.Minimum != null && value < schema.Minimum) if (schema.Minimum != null && value < schema.Minimum)
RaiseError("Float {0} is less than minimum value of {1}.".FormatWith(CultureInfo.InvariantCulture, JsonConvert.ToString(value), schema.Minimum), schema); RaiseError("Float {0} is less than minimum value of {1}.".FormatWith(CultureInfo.InvariantCulture, JsonConvert.ToString(value), schema.Minimum), schema);
if (schema.MaximumDecimals != null && MathUtils.GetDecimalPlaces(value) > schema.MaximumDecimals) if (schema.DivisibleBy != null && !IsZero(value % schema.DivisibleBy.Value))
RaiseError("Float {0} exceeds the maximum allowed number decimal places of {1}.".FormatWith(CultureInfo.InvariantCulture, JsonConvert.ToString(value), schema.MaximumDecimals), schema); RaiseError("Float {0} is not evenly divisible by {1}.".FormatWith(CultureInfo.InvariantCulture, JsonConvert.ToString(value), schema.DivisibleBy), schema);
}
private static bool IsZero(double value)
{
double epsilon = 2.2204460492503131e-016;
return Math.Abs(value) < 10.0 * epsilon;
} }
private void ValidatePropertyName(JsonSchemaModel schema) private void ValidatePropertyName(JsonSchemaModel schema)
+3 -3
View File
@@ -49,9 +49,9 @@ namespace Newtonsoft.Json.Schema
/// </summary> /// </summary>
public string Title { get; set; } public string Title { get; set; }
/// <summary> /// <summary>
/// Gets or sets whether the object is optional. /// Gets or sets whether the object is required.
/// </summary> /// </summary>
public bool? Optional { get; set; } public bool? Required { get; set; }
/// <summary> /// <summary>
/// Gets or sets whether the object is read only. /// Gets or sets whether the object is read only.
/// </summary> /// </summary>
@@ -92,7 +92,7 @@ namespace Newtonsoft.Json.Schema
/// Gets or sets the maximum decimals. /// Gets or sets the maximum decimals.
/// </summary> /// </summary>
/// <value>The maximum decimals.</value> /// <value>The maximum decimals.</value>
public int? MaximumDecimals { get; set; } public double? DivisibleBy { get; set; }
/// <summary> /// <summary>
/// Gets or sets the minimum. /// Gets or sets the minimum.
/// </summary> /// </summary>
@@ -146,8 +146,8 @@ namespace Newtonsoft.Json.Schema
case JsonSchemaConstants.AdditionalPropertiesPropertyName: case JsonSchemaConstants.AdditionalPropertiesPropertyName:
ProcessAdditionalProperties(); ProcessAdditionalProperties();
break; break;
case JsonSchemaConstants.OptionalPropertyName: case JsonSchemaConstants.RequiredPropertyName:
CurrentSchema.Optional = (bool)_reader.Value; CurrentSchema.Required = (bool)_reader.Value;
break; break;
case JsonSchemaConstants.RequiresPropertyName: case JsonSchemaConstants.RequiresPropertyName:
CurrentSchema.Requires = (string) _reader.Value; CurrentSchema.Requires = (string) _reader.Value;
@@ -173,8 +173,8 @@ namespace Newtonsoft.Json.Schema
case JsonSchemaConstants.MinimumItemsPropertyName: case JsonSchemaConstants.MinimumItemsPropertyName:
CurrentSchema.MinimumItems = Convert.ToInt32(_reader.Value, CultureInfo.InvariantCulture); CurrentSchema.MinimumItems = Convert.ToInt32(_reader.Value, CultureInfo.InvariantCulture);
break; break;
case JsonSchemaConstants.MaximumDecimalsPropertyName: case JsonSchemaConstants.DivisibleByPropertyName:
CurrentSchema.MaximumDecimals = Convert.ToInt32(_reader.Value, CultureInfo.InvariantCulture); CurrentSchema.DivisibleBy = Convert.ToDouble(_reader.Value, CultureInfo.InvariantCulture);
break; break;
case JsonSchemaConstants.DisallowPropertyName: case JsonSchemaConstants.DisallowPropertyName:
CurrentSchema.Disallow = ProcessType(); CurrentSchema.Disallow = ProcessType();
@@ -35,7 +35,7 @@ namespace Newtonsoft.Json.Schema
public const string TypePropertyName = "type"; public const string TypePropertyName = "type";
public const string PropertiesPropertyName = "properties"; public const string PropertiesPropertyName = "properties";
public const string ItemsPropertyName = "items"; public const string ItemsPropertyName = "items";
public const string OptionalPropertyName = "optional"; public const string RequiredPropertyName = "required";
public const string AdditionalPropertiesPropertyName = "additionalProperties"; public const string AdditionalPropertiesPropertyName = "additionalProperties";
public const string RequiresPropertyName = "requires"; public const string RequiresPropertyName = "requires";
public const string IdentityPropertyName = "identity"; public const string IdentityPropertyName = "identity";
@@ -54,7 +54,7 @@ namespace Newtonsoft.Json.Schema
public const string FormatPropertyName = "format"; public const string FormatPropertyName = "format";
public const string DefaultPropertyName = "default"; public const string DefaultPropertyName = "default";
public const string TransientPropertyName = "transient"; public const string TransientPropertyName = "transient";
public const string MaximumDecimalsPropertyName = "maxDecimal"; public const string DivisibleByPropertyName = "divisibleBy";
public const string HiddenPropertyName = "hidden"; public const string HiddenPropertyName = "hidden";
public const string DisallowPropertyName = "disallow"; public const string DisallowPropertyName = "disallow";
public const string ExtendsPropertyName = "extends"; public const string ExtendsPropertyName = "extends";
@@ -205,7 +205,7 @@ namespace Newtonsoft.Json.Schema
} }
} }
private JsonSchema GenerateInternal(Type type, Required valueRequired, bool optional) private JsonSchema GenerateInternal(Type type, Required valueRequired, bool required)
{ {
ValidationUtils.ArgumentNotNull(type, "type"); ValidationUtils.ArgumentNotNull(type, "type");
@@ -221,8 +221,8 @@ namespace Newtonsoft.Json.Schema
// change resolved schema to allow nulls. hacky but what are ya gonna do? // change resolved schema to allow nulls. hacky but what are ya gonna do?
if (valueRequired != Required.Always && !HasFlag(resolvedSchema.Type, JsonSchemaType.Null)) if (valueRequired != Required.Always && !HasFlag(resolvedSchema.Type, JsonSchemaType.Null))
resolvedSchema.Type |= JsonSchemaType.Null; resolvedSchema.Type |= JsonSchemaType.Null;
if (optional && resolvedSchema.Optional != true) if (required && resolvedSchema.Required != true)
resolvedSchema.Optional = true; resolvedSchema.Required = true;
return resolvedSchema; return resolvedSchema;
} }
@@ -248,8 +248,8 @@ namespace Newtonsoft.Json.Schema
if (explicitId != null) if (explicitId != null)
CurrentSchema.Id = explicitId; CurrentSchema.Id = explicitId;
if (optional) if (required)
CurrentSchema.Optional = true; CurrentSchema.Required = true;
CurrentSchema.Title = GetTitle(type); CurrentSchema.Title = GetTitle(type);
CurrentSchema.Description = GetDescription(type); CurrentSchema.Description = GetDescription(type);
@@ -364,7 +364,7 @@ namespace Newtonsoft.Json.Schema
property.ShouldSerialize != null || property.ShouldSerialize != null ||
property.GetIsSpecified != null; property.GetIsSpecified != null;
JsonSchema propertySchema = GenerateInternal(property.PropertyType, property.Required, optional); JsonSchema propertySchema = GenerateInternal(property.PropertyType, property.Required, !optional);
if (property.DefaultValue != null) if (property.DefaultValue != null)
propertySchema.Default = JToken.FromObject(property.DefaultValue); propertySchema.Default = JToken.FromObject(property.DefaultValue);
@@ -33,11 +33,11 @@ namespace Newtonsoft.Json.Schema
{ {
internal class JsonSchemaModel internal class JsonSchemaModel
{ {
public bool Optional { get; set; } public bool Required { get; set; }
public JsonSchemaType Type { get; set; } public JsonSchemaType Type { get; set; }
public int? MinimumLength { get; set; } public int? MinimumLength { get; set; }
public int? MaximumLength { get; set; } public int? MaximumLength { get; set; }
public int? MaximumDecimals { get; set; } public double? DivisibleBy { get; set; }
public double? Minimum { get; set; } public double? Minimum { get; set; }
public double? Maximum { get; set; } public double? Maximum { get; set; }
public int? MinimumItems { get; set; } public int? MinimumItems { get; set; }
@@ -54,7 +54,7 @@ namespace Newtonsoft.Json.Schema
{ {
Type = JsonSchemaType.Any; Type = JsonSchemaType.Any;
AllowAdditionalProperties = true; AllowAdditionalProperties = true;
Optional = true; Required = false;
} }
public static JsonSchemaModel Create(IList<JsonSchema> schemata) public static JsonSchemaModel Create(IList<JsonSchema> schemata)
@@ -71,12 +71,16 @@ namespace Newtonsoft.Json.Schema
private static void Combine(JsonSchemaModel model, JsonSchema schema) private static void Combine(JsonSchemaModel model, JsonSchema schema)
{ {
model.Optional = model.Optional && (schema.Optional ?? false); // Version 3 of the Draft JSON Schema has the default value of Not Required
model.Required = model.Required || (schema.Required ?? false);
model.Type = model.Type & (schema.Type ?? JsonSchemaType.Any); model.Type = model.Type & (schema.Type ?? JsonSchemaType.Any);
model.MinimumLength = MathUtils.Max(model.MinimumLength, schema.MinimumLength); model.MinimumLength = MathUtils.Max(model.MinimumLength, schema.MinimumLength);
model.MaximumLength = MathUtils.Min(model.MaximumLength, schema.MaximumLength); model.MaximumLength = MathUtils.Min(model.MaximumLength, schema.MaximumLength);
model.MaximumDecimals = MathUtils.Min(model.MaximumDecimals, schema.MaximumDecimals);
// not sure what is the best way to combine divisibleBy
model.DivisibleBy = MathUtils.Max(model.DivisibleBy, schema.DivisibleBy);
model.Minimum = MathUtils.Max(model.Minimum, schema.Minimum); model.Minimum = MathUtils.Max(model.Minimum, schema.Minimum);
model.Maximum = MathUtils.Max(model.Maximum, schema.Maximum); model.Maximum = MathUtils.Max(model.Maximum, schema.Maximum);
model.MinimumItems = MathUtils.Max(model.MinimumItems, schema.MinimumItems); model.MinimumItems = MathUtils.Max(model.MinimumItems, schema.MinimumItems);
@@ -70,7 +70,7 @@ namespace Newtonsoft.Json.Schema
WritePropertyIfNotNull(_writer, JsonSchemaConstants.IdPropertyName, schema.Id); WritePropertyIfNotNull(_writer, JsonSchemaConstants.IdPropertyName, schema.Id);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.TitlePropertyName, schema.Title); WritePropertyIfNotNull(_writer, JsonSchemaConstants.TitlePropertyName, schema.Title);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.DescriptionPropertyName, schema.Description); WritePropertyIfNotNull(_writer, JsonSchemaConstants.DescriptionPropertyName, schema.Description);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.OptionalPropertyName, schema.Optional); WritePropertyIfNotNull(_writer, JsonSchemaConstants.RequiredPropertyName, schema.Required);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.ReadOnlyPropertyName, schema.ReadOnly); WritePropertyIfNotNull(_writer, JsonSchemaConstants.ReadOnlyPropertyName, schema.ReadOnly);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.HiddenPropertyName, schema.Hidden); WritePropertyIfNotNull(_writer, JsonSchemaConstants.HiddenPropertyName, schema.Hidden);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.TransientPropertyName, schema.Transient); WritePropertyIfNotNull(_writer, JsonSchemaConstants.TransientPropertyName, schema.Transient);
@@ -107,7 +107,7 @@ namespace Newtonsoft.Json.Schema
WritePropertyIfNotNull(_writer, JsonSchemaConstants.MaximumLengthPropertyName, schema.MaximumLength); WritePropertyIfNotNull(_writer, JsonSchemaConstants.MaximumLengthPropertyName, schema.MaximumLength);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.MinimumItemsPropertyName, schema.MinimumItems); WritePropertyIfNotNull(_writer, JsonSchemaConstants.MinimumItemsPropertyName, schema.MinimumItems);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.MaximumItemsPropertyName, schema.MaximumItems); WritePropertyIfNotNull(_writer, JsonSchemaConstants.MaximumItemsPropertyName, schema.MaximumItems);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.MaximumDecimalsPropertyName, schema.MaximumDecimals); WritePropertyIfNotNull(_writer, JsonSchemaConstants.DivisibleByPropertyName, schema.DivisibleBy);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.FormatPropertyName, schema.Format); WritePropertyIfNotNull(_writer, JsonSchemaConstants.FormatPropertyName, schema.Format);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.PatternPropertyName, schema.Pattern); WritePropertyIfNotNull(_writer, JsonSchemaConstants.PatternPropertyName, schema.Pattern);
if (schema.Enum != null) if (schema.Enum != null)
@@ -743,8 +743,8 @@ namespace Newtonsoft.Json.Serialization
specifiedMember = member.DeclaringType.GetField(member.Name + JsonTypeReflector.SpecifiedPostfix); specifiedMember = member.DeclaringType.GetField(member.Name + JsonTypeReflector.SpecifiedPostfix);
if (specifiedMember == null || ReflectionUtils.GetMemberUnderlyingType(specifiedMember) != typeof(bool) if (specifiedMember == null || ReflectionUtils.GetMemberUnderlyingType(specifiedMember) != typeof(bool)
|| (ReflectionUtils.GetAttribute<XmlIgnoreAttribute>(specifiedMember) != null || (ReflectionUtils.GetAttribute<XmlIgnoreAttribute>(specifiedMember) == null
&& ReflectionUtils.GetAttribute<JsonIgnoreAttribute>(specifiedMember) != null)) && ReflectionUtils.GetAttribute<JsonIgnoreAttribute>(specifiedMember) == null))
{ {
return; return;
} }
Binary file not shown.