Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void Example()
catch (JsonSerializationException ex)
{
Console.WriteLine(ex.Message);
// Could not find member 'DeletedDate' on object of type 'Account'. Path 'DeletedDate', line 4, position 23.
// The JSON property 'DeletedDate' does not exist on object of type 'Account'. Path 'DeletedDate', line 4, position 23.
}
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public void Example()

Console.WriteLine(traceWriter.ToString());
// 2013-01-21T01:36:24.422 Info Started deserializing Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path 'FullName', line 2, position 20.
// 2013-01-21T01:36:24.442 Verbose Could not find member 'DeletedDate' on Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path 'DeletedDate', line 4, position 23.
// 2013-01-21T01:36:24.442 Verbose The JSON property 'DeletedDate' does not exist on Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path 'DeletedDate', line 4, position 23.
// 2013-01-21T01:36:24.447 Info Finished deserializing Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path '', line 5, position 8.
// 2013-01-21T01:36:24.450 Verbose Deserialized JSON:
// 2013-01-21T01:36:24.450 Verbose Deserialized JSON:
// {
// "FullName": "Dan Deleted",
// "Deleted": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void MissingMemberDeserialize()
ExceptionAssert.Throws<JsonSerializationException>(() =>
{
ProductShort deserializedProductShort = (ProductShort)JsonConvert.DeserializeObject(output, typeof(ProductShort), new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Error });
}, @"Could not find member 'Price' on object of type 'ProductShort'. Path 'Price', line 4, position 10.");
}, @"The JSON property 'Price' does not exist on object of type 'ProductShort'. Path 'Price', line 4, position 10.");
}

[Test]
Expand Down Expand Up @@ -141,7 +141,7 @@ public void MissingMemeber()
{
string json = @"{""Missing"":1}";

ExceptionAssert.Throws<JsonSerializationException>(() => { JsonConvert.DeserializeObject<DoubleClass>(json, new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Error }); }, "Could not find member 'Missing' on object of type 'DoubleClass'. Path 'Missing', line 1, position 11.");
ExceptionAssert.Throws<JsonSerializationException>(() => { JsonConvert.DeserializeObject<DoubleClass>(json, new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Error }); }, "The JSON property 'Missing' does not exist on object of type 'DoubleClass'. Path 'Missing', line 1, position 11.");
}

[Test]
Expand All @@ -160,7 +160,7 @@ public void MissingErrorAttribute()
{
string json = @"{""Missing"":1}";

ExceptionAssert.Throws<JsonSerializationException>(() => { JsonConvert.DeserializeObject<NameWithMissingError>(json); }, "Could not find member 'Missing' on object of type 'NameWithMissingError'. Path 'Missing', line 1, position 11.");
ExceptionAssert.Throws<JsonSerializationException>(() => { JsonConvert.DeserializeObject<NameWithMissingError>(json); }, "The JSON property 'Missing' does not exist on object of type 'NameWithMissingError'. Path 'Missing', line 1, position 11.");
}

[JsonObject(MissingMemberHandling = MissingMemberHandling.Error)]
Expand Down Expand Up @@ -202,7 +202,7 @@ public void MissingMemberHandling_RootObject()
JsonConvert.PopulateObject(@"{nameERROR:{""first"":""hi""}}", p, settings);

Assert.AreEqual(1, errors.Count);
Assert.AreEqual("Could not find member 'nameERROR' on object of type 'Person'. Path 'nameERROR', line 1, position 11.", errors[0]);
Assert.AreEqual("The JSON property 'nameERROR' does not exist on object of type 'Person'. Path 'nameERROR', line 1, position 11.", errors[0]);
}

[Test]
Expand All @@ -228,7 +228,7 @@ public void MissingMemberHandling_InnerObject()
JsonConvert.PopulateObject(@"{name:{""firstERROR"":""hi""}}", p, settings);

Assert.AreEqual(1, errors.Count);
Assert.AreEqual("Could not find member 'firstERROR' on object of type 'Name'. Path 'name.firstERROR', line 1, position 20.", errors[0]);
Assert.AreEqual("The JSON property 'firstERROR' does not exist on object of type 'Name'. Path 'name.firstERROR', line 1, position 20.", errors[0]);
}

[JsonObject(MissingMemberHandling = MissingMemberHandling.Ignore)]
Expand Down Expand Up @@ -269,7 +269,7 @@ public void TestMissingMemberHandlingForChildObjectsWithInvalidData()
ExceptionAssert.Throws<JsonSerializationException>(() =>
{
JsonConvert.DeserializeObject<ObjectWithExtendableChild>(json, new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Error });
}, "Could not find member 'InvalidData' on object of type 'ObjectWithExtendableChild'. Path 'InvalidData', line 1, position 15.");
}, "The JSON property 'InvalidData' does not exist on object of type 'ObjectWithExtendableChild'. Path 'InvalidData', line 1, position 15.");
}
}
}
8 changes: 4 additions & 4 deletions Src/Newtonsoft.Json.Tests/Serialization/TraceWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#endif

namespace Newtonsoft.Json.Tests.Serialization
{
{
public class Staff
{
public string Name { get; set; }
Expand Down Expand Up @@ -356,7 +356,7 @@ public void MemoryTraceWriterDeserializeTest()
// 2012-11-11T12:08:42.797 Info Started serializing System.Collections.Generic.List`1[System.String]. Path 'Roles'.
// 2012-11-11T12:08:42.798 Info Finished serializing System.Collections.Generic.List`1[System.String]. Path 'Roles'.
// 2012-11-11T12:08:42.799 Info Finished serializing Newtonsoft.Json.Tests.Serialization.Staff. Path ''.
// 2013-05-19T00:07:24.360 Verbose Deserialized JSON:
// 2013-05-19T00:07:24.360 Verbose Deserialized JSON:
// {
// "Name": "Arnie Admin",
// "StartDate": new Date(
Expand Down Expand Up @@ -917,7 +917,7 @@ public void DeserializeMissingMember()
});

Assert.AreEqual("Started deserializing Newtonsoft.Json.Tests.TestObjects.Organization.Person. Path 'MissingMemberProperty', line 1, position 25.", traceWriter.TraceRecords[0].Message);
Assert.AreEqual("Could not find member 'MissingMemberProperty' on Newtonsoft.Json.Tests.TestObjects.Organization.Person. Path 'MissingMemberProperty', line 1, position 25.", traceWriter.TraceRecords[1].Message);
Assert.AreEqual("The JSON property 'MissingMemberProperty' does not exist on Newtonsoft.Json.Tests.TestObjects.Organization.Person. Path 'MissingMemberProperty', line 1, position 25.", traceWriter.TraceRecords[1].Message);
Assert.IsTrue(traceWriter.TraceRecords[2].Message.StartsWith("Finished deserializing Newtonsoft.Json.Tests.TestObjects.Organization.Person. Path ''"));
}

Expand Down Expand Up @@ -945,7 +945,7 @@ public void DeserializeMissingMemberConstructor()
});

Assert.AreEqual("Deserializing Newtonsoft.Json.Tests.TestObjects.VersionOld using creator with parameters: Major, Minor, Build, Revision. Path 'Major', line 2, position 10.", traceWriter.TraceRecords[0].Message);
Assert.AreEqual("Could not find member 'MissingMemberProperty' on Newtonsoft.Json.Tests.TestObjects.VersionOld. Path 'MissingMemberProperty', line 8, position 31.", traceWriter.TraceRecords[1].Message);
Assert.AreEqual("The JSON property 'MissingMemberProperty' does not exist on Newtonsoft.Json.Tests.TestObjects.VersionOld. Path 'MissingMemberProperty', line 8, position 31.", traceWriter.TraceRecords[1].Message);
Assert.IsTrue(traceWriter.TraceRecords[2].Message.StartsWith("Started deserializing Newtonsoft.Json.Tests.TestObjects.VersionOld. Path ''"));
Assert.IsTrue(traceWriter.TraceRecords[3].Message.StartsWith("Finished deserializing Newtonsoft.Json.Tests.TestObjects.VersionOld. Path ''"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2282,7 +2282,7 @@ private List<CreatorPropertyContext> ResolvePropertyAndCreatorValues(JsonObjectC
{
creatorPropertyContext.Value = CreateValueInternal(reader, property.PropertyType, property.PropertyContract, property, contract, containerProperty, null);
}

continue;
}
else
Expand All @@ -2302,12 +2302,12 @@ private List<CreatorPropertyContext> ResolvePropertyAndCreatorValues(JsonObjectC

if (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Verbose)
{
TraceWriter.Trace(TraceLevel.Verbose, JsonPosition.FormatMessage(reader as IJsonLineInfo, reader.Path, "Could not find member '{0}' on {1}.".FormatWith(CultureInfo.InvariantCulture, memberName, contract.UnderlyingType)), null);
TraceWriter.Trace(TraceLevel.Verbose, JsonPosition.FormatMessage(reader as IJsonLineInfo, reader.Path, "The JSON property '{0}' does not exist on {1}.".FormatWith(CultureInfo.InvariantCulture, memberName, contract.UnderlyingType)), null);
}

if ((contract.MissingMemberHandling ?? Serializer._missingMemberHandling) == MissingMemberHandling.Error)
{
throw JsonSerializationException.Create(reader, "Could not find member '{0}' on object of type '{1}'".FormatWith(CultureInfo.InvariantCulture, memberName, objectType.Name));
throw JsonSerializationException.Create(reader, "The JSON property '{0}' does not exist on object of type '{1}'".FormatWith(CultureInfo.InvariantCulture, memberName, objectType.Name));
}
}

Expand Down Expand Up @@ -2425,12 +2425,12 @@ private object PopulateObject(object newObject, JsonReader reader, JsonObjectCon
{
if (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Verbose)
{
TraceWriter.Trace(TraceLevel.Verbose, JsonPosition.FormatMessage(reader as IJsonLineInfo, reader.Path, "Could not find member '{0}' on {1}".FormatWith(CultureInfo.InvariantCulture, propertyName, contract.UnderlyingType)), null);
TraceWriter.Trace(TraceLevel.Verbose, JsonPosition.FormatMessage(reader as IJsonLineInfo, reader.Path, "The JSON property '{0}' does not exist on {1}".FormatWith(CultureInfo.InvariantCulture, propertyName, contract.UnderlyingType)), null);
}

if ((contract.MissingMemberHandling ?? Serializer._missingMemberHandling) == MissingMemberHandling.Error)
{
throw JsonSerializationException.Create(reader, "Could not find member '{0}' on object of type '{1}'".FormatWith(CultureInfo.InvariantCulture, propertyName, contract.UnderlyingType.Name));
throw JsonSerializationException.Create(reader, "The JSON property '{0}' does not exist on object of type '{1}'".FormatWith(CultureInfo.InvariantCulture, propertyName, contract.UnderlyingType.Name));
}

if (!reader.Read())
Expand Down