-Fix error message for missing member
-Fix exception not throwing for bad char after semi-colon
This commit is contained in:
@@ -1024,6 +1024,15 @@ keyword such as type of business.""
|
|||||||
Assert.AreEqual(1, c.Height);
|
Assert.AreEqual(1, c.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = "Could not find member 'Missing' on object of type 'DoubleClass'")]
|
||||||
|
public void MissingMemeber()
|
||||||
|
{
|
||||||
|
string json = @"{""Missing"":1}";
|
||||||
|
|
||||||
|
JsonConvert.DeserializeObject<DoubleClass>(json);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void SerializeTypeProperty()
|
public void SerializeTypeProperty()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -445,5 +445,29 @@ namespace Newtonsoft.Json.Tests
|
|||||||
Assert.AreEqual(JsonToken.EndArray, jsonReader.TokenType);
|
Assert.AreEqual(JsonToken.EndArray, jsonReader.TokenType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = @"Invalid character after parsing property name. Expected ':' but got: "". Line 3, position 9.")]
|
||||||
|
public void MissingColon()
|
||||||
|
{
|
||||||
|
string json = @"{
|
||||||
|
""A"" : true,
|
||||||
|
""B"" ""hello"", // Notice the colon is missing
|
||||||
|
""C"" : ""bye""
|
||||||
|
}";
|
||||||
|
|
||||||
|
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||||
|
|
||||||
|
reader.Read();
|
||||||
|
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
|
||||||
|
|
||||||
|
reader.Read();
|
||||||
|
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||||
|
|
||||||
|
reader.Read();
|
||||||
|
Assert.AreEqual(JsonToken.Boolean, reader.TokenType);
|
||||||
|
|
||||||
|
reader.Read();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -423,7 +423,7 @@ namespace Newtonsoft.Json
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (_missingMemberHandling == MissingMemberHandling.Error)
|
if (_missingMemberHandling == MissingMemberHandling.Error)
|
||||||
throw new JsonSerializationException("Could not find member '{0}' on object of type '{1}'".FormatWith(CultureInfo.InvariantCulture, memberName, targetType.GetType().Name));
|
throw new JsonSerializationException("Could not find member '{0}' on object of type '{1}'".FormatWith(CultureInfo.InvariantCulture, memberName, targetType.Name));
|
||||||
|
|
||||||
reader.Skip();
|
reader.Skip();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -275,16 +275,6 @@ namespace Newtonsoft.Json
|
|||||||
_currentChar = '\0';
|
_currentChar = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool MoveTo(char value)
|
|
||||||
{
|
|
||||||
while (MoveNext())
|
|
||||||
{
|
|
||||||
if (_currentChar == value)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads the next Json token from the stream.
|
/// Reads the next Json token from the stream.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -424,10 +414,15 @@ namespace Newtonsoft.Json
|
|||||||
throw CreateJsonReaderException("Invalid property identifier character: {0}. Line {1}, position {2}.", _currentChar, _currentLineNumber, _currentLinePosition);
|
throw CreateJsonReaderException("Invalid property identifier character: {0}. Line {1}, position {2}.", _currentChar, _currentLineNumber, _currentLinePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
// finished property. move to colon
|
|
||||||
if (_currentChar != ':')
|
if (_currentChar != ':')
|
||||||
{
|
{
|
||||||
MoveTo(':');
|
MoveNext();
|
||||||
|
|
||||||
|
// finished property. skip any whitespace and move to colon
|
||||||
|
EatWhitespace(false);
|
||||||
|
|
||||||
|
if (_currentChar != ':')
|
||||||
|
throw CreateJsonReaderException("Invalid character after parsing property name. Expected ':' but got: {0}. Line {1}, position {2}.", _currentChar, _currentLineNumber, _currentLinePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetToken(JsonToken.PropertyName, _buffer.ToString());
|
SetToken(JsonToken.PropertyName, _buffer.ToString());
|
||||||
|
|||||||
Reference in New Issue
Block a user