diff options
author | James Newton-King <james@newtonking.com> | 2012-02-25 07:44:07 +0400 |
---|---|---|
committer | James Newton-King <james@newtonking.com> | 2012-02-25 07:44:07 +0400 |
commit | fb2a5998bc2e85bde77ab157c5d30eb4791d809f (patch) | |
tree | deb4f6981a0c1f546b8addbbc895c40ce24b62a9 | |
parent | 0d6ad0b76ed3b97275122a3bda8171b31cac53e8 (diff) |
-Added Path to JsonReaderException, JsonSchemaException and ValidationEventArgs
-Fixed Path on JsonValidatingReader
-Fixed path queries over constructors
-rw-r--r-- | Src/Newtonsoft.Json.Tests/JsonValidatingReaderTests.cs | 36 | ||||
-rw-r--r-- | Src/Newtonsoft.Json.Tests/Linq/JPathTests.cs | 35 | ||||
-rw-r--r-- | Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs | 2 | ||||
-rw-r--r-- | Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs | 5 | ||||
-rw-r--r-- | Src/Newtonsoft.Json.Tests/Schema/JsonSchemaTests.cs | 1 | ||||
-rw-r--r-- | Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs | 26 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/JsonReader.cs | 22 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/JsonReaderException.cs | 9 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/JsonValidatingReader.cs | 10 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Linq/JPath.cs | 13 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Properties/AssemblyInfo.cs | 2 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Schema/JsonSchemaException.cs | 9 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Schema/ValidationEventArgs.cs | 15 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Serialization/ErrorContext.cs | 4 |
14 files changed, 142 insertions, 47 deletions
diff --git a/Src/Newtonsoft.Json.Tests/JsonValidatingReaderTests.cs b/Src/Newtonsoft.Json.Tests/JsonValidatingReaderTests.cs index c272996..b8950d7 100644 --- a/Src/Newtonsoft.Json.Tests/JsonValidatingReaderTests.cs +++ b/Src/Newtonsoft.Json.Tests/JsonValidatingReaderTests.cs @@ -50,16 +50,17 @@ namespace Newtonsoft.Json.Tests JsonSchema schema = JsonSchema.Parse(schemaJson);
reader.Schema = schema;
Assert.AreEqual(schema, reader.Schema);
-
Assert.AreEqual(0, reader.Depth);
+ Assert.AreEqual("", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
+ Assert.AreEqual("", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
Assert.AreEqual("name", reader.Value.ToString());
-
+ Assert.AreEqual("name", reader.Path);
Assert.AreEqual(1, reader.Depth);
Assert.IsTrue(reader.Read());
@@ -67,30 +68,39 @@ namespace Newtonsoft.Json.Tests Assert.AreEqual("James", reader.Value.ToString());
Assert.AreEqual(typeof (string), reader.ValueType);
Assert.AreEqual('"', reader.QuoteChar);
+ Assert.AreEqual("name", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
Assert.AreEqual("hobbies", reader.Value.ToString());
Assert.AreEqual('\'', reader.QuoteChar);
+ Assert.AreEqual("hobbies", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
+ Assert.AreEqual("hobbies", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.String, reader.TokenType);
Assert.AreEqual("pie", reader.Value.ToString());
Assert.AreEqual('"', reader.QuoteChar);
+ Assert.AreEqual("hobbies[0]", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.String, reader.TokenType);
Assert.AreEqual("cake", reader.Value.ToString());
+ Assert.AreEqual("hobbies[1]", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
+ Assert.AreEqual("hobbies", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
+ Assert.AreEqual("", reader.Path);
+ Assert.IsFalse(reader.Read());
+
Assert.IsNull(validationEventArgs);
}
@@ -248,6 +258,7 @@ namespace Newtonsoft.Json.Tests Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.String, reader.TokenType);
Assert.AreEqual(@"Value ""THREE"" is not defined in enum. Line 1, position 20.", validationEventArgs.Message);
+ Assert.AreEqual("[2]", validationEventArgs.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
@@ -274,6 +285,7 @@ namespace Newtonsoft.Json.Tests Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.String, reader.TokenType);
Assert.AreEqual("String 'The quick brown fox jumps over the lazy dog.' does not match regex pattern 'foo'. Line 1, position 46.", validationEventArgs.Message);
+ Assert.AreEqual("", validationEventArgs.Path);
Assert.IsNotNull(validationEventArgs);
}
@@ -297,6 +309,7 @@ namespace Newtonsoft.Json.Tests Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
Assert.AreEqual("Integer 10 exceeds maximum value of 5. Line 1, position 2.", validationEventArgs.Message);
+ Assert.AreEqual("", validationEventArgs.Path);
Assert.IsNotNull(validationEventArgs);
}
@@ -372,6 +385,7 @@ namespace Newtonsoft.Json.Tests Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
Assert.AreEqual(@"Value 3 is not defined in enum. Line 1, position 6.", validationEventArgs.Message);
+ Assert.AreEqual("[2]", validationEventArgs.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
@@ -458,6 +472,7 @@ namespace Newtonsoft.Json.Tests Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(@"Value 3.0 is not defined in enum. Line 1, position 12.", validationEventArgs.Message);
+ Assert.AreEqual("[2]", validationEventArgs.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
@@ -497,6 +512,7 @@ namespace Newtonsoft.Json.Tests Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(@"Float 4.001 is not evenly divisible by 0.1. Line 1, position 14.", validationEventArgs.Message);
+ Assert.AreEqual("[2]", validationEventArgs.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
@@ -560,6 +576,7 @@ namespace Newtonsoft.Json.Tests Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Null, reader.TokenType);
Assert.AreEqual(@"Value null is not defined in enum. Line 1, position 5.", validationEventArgs.Message);
+ Assert.AreEqual("[0]", validationEventArgs.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
@@ -597,6 +614,7 @@ namespace Newtonsoft.Json.Tests Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Boolean, reader.TokenType);
Assert.AreEqual(@"Value false is not defined in enum. Line 1, position 11.", validationEventArgs.Message);
+ Assert.AreEqual("[1]", validationEventArgs.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
@@ -768,6 +786,7 @@ namespace Newtonsoft.Json.Tests Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
Assert.AreEqual("Required properties are missing from object: hobbies, age. Line 1, position 16.", validationEventArgs.Message);
+ Assert.AreEqual("", validationEventArgs.Path);
Assert.IsNotNull(validationEventArgs);
}
@@ -1182,7 +1201,7 @@ namespace Newtonsoft.Json.Tests reader.ValidationEventHandler += (sender, args) =>
{
validationEventArgs = args;
- errors.Add(validationEventArgs.Message);
+ errors.Add(validationEventArgs.Path + " - " + validationEventArgs.Message);
};
reader.Schema = secondSchema;
@@ -1206,7 +1225,7 @@ namespace Newtonsoft.Json.Tests Assert.AreEqual(JsonToken.String, reader.TokenType);
Assert.AreEqual("secasecasecasecaseca", reader.Value.ToString());
Assert.AreEqual(1, errors.Count);
- Assert.AreEqual("String 'secasecasecasecaseca' exceeds maximum length of 10. Line 3, position 42.", errors[0]);
+ Assert.AreEqual("secondproperty - String 'secasecasecasecaseca' exceeds maximum length of 10. Line 3, position 42.", errors[0]);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
@@ -1226,9 +1245,9 @@ namespace Newtonsoft.Json.Tests Assert.AreEqual(JsonToken.String, reader.TokenType);
Assert.AreEqual("aaa", reader.Value.ToString());
Assert.AreEqual(4, errors.Count);
- Assert.AreEqual("String 'aaa' is less than minimum length of 7. Line 5, position 40.", errors[1]);
- Assert.AreEqual("String 'aaa' does not match regex pattern 'hi'. Line 5, position 40.", errors[2]);
- Assert.AreEqual("String 'aaa' does not match regex pattern 'hi2u'. Line 5, position 40.", errors[3]);
+ Assert.AreEqual("thirdproperty.thirdproperty_firstproperty - String 'aaa' is less than minimum length of 7. Line 5, position 40.", errors[1]);
+ Assert.AreEqual("thirdproperty.thirdproperty_firstproperty - String 'aaa' does not match regex pattern 'hi'. Line 5, position 40.", errors[2]);
+ Assert.AreEqual("thirdproperty.thirdproperty_firstproperty - String 'aaa' does not match regex pattern 'hi2u'. Line 5, position 40.", errors[3]);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
@@ -1239,7 +1258,7 @@ namespace Newtonsoft.Json.Tests Assert.AreEqual(JsonToken.String, reader.TokenType);
Assert.AreEqual("three", reader.Value.ToString());
Assert.AreEqual(5, errors.Count);
- Assert.AreEqual("String 'three' is less than minimum length of 6. Line 6, position 25.", errors[4]);
+ Assert.AreEqual("thirdproperty.additional - String 'three' is less than minimum length of 6. Line 6, position 25.", errors[4]);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
@@ -1487,6 +1506,7 @@ namespace Newtonsoft.Json.Tests reader.ReadAsInt32();
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
Assert.AreEqual("Array item count 2 exceeds maximum count of 1. Line 1, position 5.", validationEventArgs.Message);
+ Assert.AreEqual("", validationEventArgs.Path);
}
[Test]
diff --git a/Src/Newtonsoft.Json.Tests/Linq/JPathTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JPathTests.cs index 1d699a5..08031be 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JPathTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JPathTests.cs @@ -181,8 +181,8 @@ namespace Newtonsoft.Json.Tests.Linq }
[Test]
- [ExpectedException(typeof(Exception), ExpectedMessage = @"Index 1 not valid on JConstructor.")]
- public void EvaluateIndexerOnConstructorWithError()
+ [ExpectedException(typeof(IndexOutOfRangeException), ExpectedMessage = @"Index 1 outside the bounds of JConstructor.")]
+ public void EvaluateConstructorOutOfBoundsIndxerWithError()
{
JConstructor c = new JConstructor("Blah");
@@ -210,7 +210,7 @@ namespace Newtonsoft.Json.Tests.Linq [Test]
[ExpectedException(typeof(IndexOutOfRangeException), ExpectedMessage = "Index 1000 outside the bounds of JArray.")]
- public void EvaluateOutOfBoundsIndxerWithError()
+ public void EvaluateArrayOutOfBoundsIndxerWithError()
{
JArray a = new JArray(1, 2, 3, 4, 5);
@@ -253,6 +253,35 @@ namespace Newtonsoft.Json.Tests.Linq }
[Test]
+ public void PathWithConstructor()
+ {
+ JArray a = JArray.Parse(@"[
+ {
+ ""Property1"": [
+ 1,
+ [
+ [
+ []
+ ]
+ ]
+ ]
+ },
+ {
+ ""Property2"": new Constructor1(
+ null,
+ [
+ 1
+ ]
+ )
+ }
+]");
+
+ JValue v = (JValue)a.SelectToken("[1].Property2[1][0]");
+ Assert.AreEqual(1, v.Value);
+ }
+
+
+ [Test]
public void Example()
{
JObject o = JObject.Parse(@"{
diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index f34065e..4a503e7 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -72,5 +72,5 @@ using System.Security; // by using the '*' as shown below:
[assembly: AssemblyVersion("4.0.8.0")]
#if !PocketPC
-[assembly: AssemblyFileVersion("4.0.8.14623")]
+[assembly: AssemblyFileVersion("4.0.8.14625")]
#endif
diff --git a/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs b/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs index 99f3a5b..36e042a 100644 --- a/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs +++ b/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs @@ -113,9 +113,10 @@ namespace Newtonsoft.Json.Tests.Schema JObject o = JObject.Parse("{'lol':1}");
List<string> errors = new List<string>();
- o.Validate(schema, (sender, args) => errors.Add(args.Message));
+ o.Validate(schema, (sender, args) => errors.Add(args.Path + " - " + args.Message));
- Assert.AreEqual("Invalid type. Expected String but got Integer. Line 1, position 8.", errors[0]);
+ Assert.AreEqual("lol - Invalid type. Expected String but got Integer. Line 1, position 8.", errors[0]);
+ Assert.AreEqual("1", o.SelectToken("lol").ToString());
Assert.AreEqual(1, errors.Count);
}
diff --git a/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaTests.cs b/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaTests.cs index 0e31a1e..959560b 100644 --- a/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaTests.cs +++ b/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaTests.cs @@ -113,6 +113,7 @@ namespace Newtonsoft.Json.Tests.Schema }
}", writtenJson);
}
+
[Test]
public void WriteTo_AdditionalProperties()
{
diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index 015fac8..39b3103 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -5180,7 +5180,7 @@ keyword such as type of business."" }
[Test]
- [ExpectedException(typeof(JsonSerializationException), ExpectedMessage = "Unexpected end when setting PreProperty's value. Line 2, position 18.")]
+ [ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "Unexpected end when setting PreProperty's value. Line 2, position 18.")]
public void DeserializeUnexpectedEndInt()
{
string json = @"{
@@ -5263,10 +5263,10 @@ keyword such as type of business."" Assert.AreEqual(null, e.NullableEnum);
json = JsonConvert.SerializeObject(new WithEnums
- {
- Id = 7,
- NullableEnum = MyEnum.Value2
- });
+ {
+ Id = 7,
+ NullableEnum = MyEnum.Value2
+ });
Assert.AreEqual(@"{""Id"":7,""NullableEnum"":1}", json);
@@ -5278,13 +5278,13 @@ keyword such as type of business."" [Test]
public void NullableStructWithConverter()
{
- string json = JsonConvert.SerializeObject(new Widget1 { Id = new WidgetId1 { Value = 1234 } });
+ string json = JsonConvert.SerializeObject(new Widget1 {Id = new WidgetId1 {Value = 1234}});
Assert.AreEqual(@"{""Id"":""1234""}", json);
Widget1 w = JsonConvert.DeserializeObject<Widget1>(@"{""Id"":""1234""}");
- Assert.AreEqual(new WidgetId1 { Value = 1234 }, w.Id);
+ Assert.AreEqual(new WidgetId1 {Value = 1234}, w.Id);
}
[Test]
@@ -5330,21 +5330,21 @@ keyword such as type of business."" }
[Test]
- [ExpectedException(typeof(JsonSerializationException), ExpectedMessage = "No JSON content found and type 'System.Double' is not nullable.")]
+ [ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "No JSON content found and type 'System.Double' is not nullable.")]
public void DeserializeDoubleFromEmptyString()
{
JsonConvert.DeserializeObject<double>("");
}
[Test]
- [ExpectedException(typeof(JsonSerializationException), ExpectedMessage = "No JSON content found and type 'System.StringComparison' is not nullable.")]
+ [ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "No JSON content found and type 'System.StringComparison' is not nullable.")]
public void DeserializeEnumFromEmptyString()
{
JsonConvert.DeserializeObject<StringComparison>("");
}
[Test]
- [ExpectedException(typeof(JsonSerializationException), ExpectedMessage = "No JSON content found and type 'System.Int32' is not nullable.")]
+ [ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "No JSON content found and type 'System.Int32' is not nullable.")]
public void DeserializeInt32FromEmptyString()
{
JsonConvert.DeserializeObject<int>("");
@@ -5358,7 +5358,7 @@ keyword such as type of business."" }
[Test]
- [ExpectedException(typeof(ArgumentNullException), ExpectedMessage = @"Value cannot be null.
+ [ExpectedException(typeof (ArgumentNullException), ExpectedMessage = @"Value cannot be null.
Parameter name: value")]
public void DeserializeDoubleFromNullString()
{
@@ -5366,12 +5366,12 @@ Parameter name: value")] }
[Test]
- [ExpectedException(typeof(ArgumentNullException), ExpectedMessage = @"Value cannot be null.
+ [ExpectedException(typeof (ArgumentNullException), ExpectedMessage = @"Value cannot be null.
Parameter name: value")]
public void DeserializeFromNullString()
{
JsonConvert.DeserializeObject(null);
- }
+ }
}
public class Widget1
diff --git a/Src/Newtonsoft.Json/JsonReader.cs b/Src/Newtonsoft.Json/JsonReader.cs index edcc989..691ac82 100644 --- a/Src/Newtonsoft.Json/JsonReader.cs +++ b/Src/Newtonsoft.Json/JsonReader.cs @@ -242,18 +242,9 @@ namespace Newtonsoft.Json }
/// <summary>
- /// Gets or sets the culture used when reading JSON. Defaults to <see cref="CultureInfo.InvariantCulture"/>.
- /// </summary>
- public CultureInfo Culture
- {
- get { return _culture ?? CultureInfo.InvariantCulture; }
- set { _culture = value; }
- }
-
- /// <summary>
/// Gets the path of the current JSON token.
/// </summary>
- public string Path
+ public virtual string Path
{
get
{
@@ -265,6 +256,15 @@ namespace Newtonsoft.Json }
/// <summary>
+ /// Gets or sets the culture used when reading JSON. Defaults to <see cref="CultureInfo.InvariantCulture"/>.
+ /// </summary>
+ public CultureInfo Culture
+ {
+ get { return _culture ?? CultureInfo.InvariantCulture; }
+ set { _culture = value; }
+ }
+
+ /// <summary>
/// Initializes a new instance of the <see cref="JsonReader"/> class with the specified <see cref="TextReader"/>.
/// </summary>
protected JsonReader()
@@ -596,7 +596,7 @@ namespace Newtonsoft.Json linePosition = 0;
}
- return new JsonReaderException(message, ex, lineNumber, linePosition);
+ return new JsonReaderException(message, ex, Path, lineNumber, linePosition);
}
internal static string FormatExceptionMessage(IJsonLineInfo lineInfo, string message)
diff --git a/Src/Newtonsoft.Json/JsonReaderException.cs b/Src/Newtonsoft.Json/JsonReaderException.cs index 4ea4a8d..e10f39a 100644 --- a/Src/Newtonsoft.Json/JsonReaderException.cs +++ b/Src/Newtonsoft.Json/JsonReaderException.cs @@ -50,6 +50,12 @@ namespace Newtonsoft.Json public int LinePosition { get; private set; }
/// <summary>
+ /// Gets the path to the JSON where the error occurred.
+ /// </summary>
+ /// <value>The path to the JSON where the error occurred.</value>
+ public string Path { get; private set; }
+
+ /// <summary>
/// Initializes a new instance of the <see cref="JsonReaderException"/> class.
/// </summary>
public JsonReaderException()
@@ -91,9 +97,10 @@ namespace Newtonsoft.Json }
#endif
- internal JsonReaderException(string message, Exception innerException, int lineNumber, int linePosition)
+ internal JsonReaderException(string message, Exception innerException, string path, int lineNumber, int linePosition)
: base(message, innerException)
{
+ Path = path;
LineNumber = lineNumber;
LinePosition = linePosition;
}
diff --git a/Src/Newtonsoft.Json/JsonValidatingReader.cs b/Src/Newtonsoft.Json/JsonValidatingReader.cs index 8c60fd8..15c5ff4 100644 --- a/Src/Newtonsoft.Json/JsonValidatingReader.cs +++ b/Src/Newtonsoft.Json/JsonValidatingReader.cs @@ -112,6 +112,14 @@ namespace Newtonsoft.Json }
/// <summary>
+ /// Gets the path of the current JSON token.
+ /// </summary>
+ public override string Path
+ {
+ get { return _reader.Path; }
+ }
+
+ /// <summary>
/// Gets the quotation mark character used to enclose the value of a string.
/// </summary>
/// <value></value>
@@ -246,7 +254,7 @@ namespace Newtonsoft.Json ? message + " Line {0}, position {1}.".FormatWith(CultureInfo.InvariantCulture, lineInfo.LineNumber, lineInfo.LinePosition)
: message;
- OnValidationEvent(new JsonSchemaException(exceptionMessage, null, lineInfo.LineNumber, lineInfo.LinePosition));
+ OnValidationEvent(new JsonSchemaException(exceptionMessage, null, Path, lineInfo.LineNumber, lineInfo.LinePosition));
}
private void OnValidationEvent(JsonSchemaException exception)
diff --git a/Src/Newtonsoft.Json/Linq/JPath.cs b/Src/Newtonsoft.Json/Linq/JPath.cs index c0279b9..d110bbc 100644 --- a/Src/Newtonsoft.Json/Linq/JPath.cs +++ b/Src/Newtonsoft.Json/Linq/JPath.cs @@ -141,6 +141,7 @@ namespace Newtonsoft.Json.Linq int index = (int) part;
JArray a = current as JArray;
+ JConstructor c = current as JConstructor;
if (a != null)
{
@@ -154,6 +155,18 @@ namespace Newtonsoft.Json.Linq current = a[index];
}
+ else if (c != null)
+ {
+ if (c.Count <= index)
+ {
+ if (errorWhenNoMatch)
+ throw new IndexOutOfRangeException("Index {0} outside the bounds of JConstructor.".FormatWith(CultureInfo.InvariantCulture, index));
+
+ return null;
+ }
+
+ current = c[index];
+ }
else
{
if (errorWhenNoMatch)
diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index b1bc331..0e73afb 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -85,7 +85,7 @@ using System.Security; // by using the '*' as shown below:
[assembly: AssemblyVersion("4.0.8.0")]
#if !PocketPC
-[assembly: AssemblyFileVersion("4.0.8.14623")]
+[assembly: AssemblyFileVersion("4.0.8.14625")]
#endif
[assembly: CLSCompliant(true)]
diff --git a/Src/Newtonsoft.Json/Schema/JsonSchemaException.cs b/Src/Newtonsoft.Json/Schema/JsonSchemaException.cs index 86d2924..5699d38 100644 --- a/Src/Newtonsoft.Json/Schema/JsonSchemaException.cs +++ b/Src/Newtonsoft.Json/Schema/JsonSchemaException.cs @@ -50,6 +50,12 @@ namespace Newtonsoft.Json.Schema public int LinePosition { get; private set; }
/// <summary>
+ /// Gets the path to the JSON where the error occurred.
+ /// </summary>
+ /// <value>The path to the JSON where the error occurred.</value>
+ public string Path { get; private set; }
+
+ /// <summary>
/// Initializes a new instance of the <see cref="JsonSchemaException"/> class.
/// </summary>
public JsonSchemaException()
@@ -91,9 +97,10 @@ namespace Newtonsoft.Json.Schema }
#endif
- internal JsonSchemaException(string message, Exception innerException, int lineNumber, int linePosition)
+ internal JsonSchemaException(string message, Exception innerException, string path, int lineNumber, int linePosition)
: base(message, innerException)
{
+ Path = path;
LineNumber = lineNumber;
LinePosition = linePosition;
}
diff --git a/Src/Newtonsoft.Json/Schema/ValidationEventArgs.cs b/Src/Newtonsoft.Json/Schema/ValidationEventArgs.cs index 3b2b107..77169bc 100644 --- a/Src/Newtonsoft.Json/Schema/ValidationEventArgs.cs +++ b/Src/Newtonsoft.Json/Schema/ValidationEventArgs.cs @@ -42,16 +42,25 @@ namespace Newtonsoft.Json.Schema }
/// <summary>
- /// Gets the <see cref="JsonSchemaException"/> associated with the validation event.
+ /// Gets the <see cref="JsonSchemaException"/> associated with the validation error.
/// </summary>
- /// <value>The JsonSchemaException associated with the validation event.</value>
+ /// <value>The JsonSchemaException associated with the validation error.</value>
public JsonSchemaException Exception
{
get { return _ex; }
}
/// <summary>
- /// Gets the text description corresponding to the validation event.
+ /// Gets the path of the JSON location where the validation error occurred.
+ /// </summary>
+ /// <value>The path of the JSON location where the validation error occurred.</value>
+ public string Path
+ {
+ get { return _ex.Path; }
+ }
+
+ /// <summary>
+ /// Gets the text description corresponding to the validation error.
/// </summary>
/// <value>The text description.</value>
public string Message
diff --git a/Src/Newtonsoft.Json/Serialization/ErrorContext.cs b/Src/Newtonsoft.Json/Serialization/ErrorContext.cs index 28f7ad5..75cc87b 100644 --- a/Src/Newtonsoft.Json/Serialization/ErrorContext.cs +++ b/Src/Newtonsoft.Json/Serialization/ErrorContext.cs @@ -59,9 +59,9 @@ namespace Newtonsoft.Json.Serialization /// <value>The member that caused the error.</value>
public object Member { get; private set; }
/// <summary>
- /// Gets the path of the JSON location when the error occurred.
+ /// Gets the path of the JSON location where the error occurred.
/// </summary>
- /// <value>The path of the JSON location when the error occurred.</value>
+ /// <value>The path of the JSON location where the error occurred.</value>
public string Path { get; private set; }
/// <summary>
/// Gets or sets a value indicating whether this <see cref="ErrorContext"/> is handled.
|