Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues that are variants of those #1182 #1184

Merged
merged 2 commits into from
Jan 18, 2017
Merged

Fix issues that are variants of those #1182 #1184

merged 2 commits into from
Jan 18, 2017

Conversation

JonHanna
Copy link
Contributor

Fix issues similar to #1182 in JToken and derived types.

Include line information in exception.

@@ -962,9 +962,15 @@ public static void PopulateObject(string value, object target, JsonSerializerSet
{
jsonSerializer.Populate(jsonReader, target);

if (jsonReader.Read() && jsonReader.TokenType != JsonToken.Comment)
if (settings != null && settings.CheckAdditionalContent)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this check because it seems that the current behaviour of throwing when there isn't a setting requesting it is, given that such a setting exists and is available to the user, a bug in itself. Maybe I'm misinterpreting the intent here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that makes sense.

{
throw JsonReaderException.Create(reader, "Additional text found in JSON string after parsing content.");
if (reader.TokenType != JsonToken.Comment)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also throw if settings.CommentHandling == CommentHandling.Load?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. That is specific to comments in arrays. It really just exists as a backwards compatibility toggle for older bad behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. That makes that whole setting make more sense now :)

Copy link
Owner

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One change, plus need tests.

{
if (jsonReader.TokenType != JsonToken.Comment)
{
throw new JsonSerializationException("Additional text found in JSON string after finishing deserializing object.");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this exception to use JsonSerializationException.Create(reader, "blah blah")

{
throw JsonReaderException.Create(reader, "Additional text found in JSON string after parsing content.");
if (reader.TokenType != JsonToken.Comment)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. That is specific to comments in arrays. It really just exists as a backwards compatibility toggle for older bad behavior.

@@ -962,9 +962,15 @@ public static void PopulateObject(string value, object target, JsonSerializerSet
{
jsonSerializer.Populate(jsonReader, target);

if (jsonReader.Read() && jsonReader.TokenType != JsonToken.Comment)
if (settings != null && settings.CheckAdditionalContent)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that makes sense.

@JamesNK
Copy link
Owner

JamesNK commented Jan 16, 2017

Changes look good.

I'd like tests of the new behavior - exceptions with more detail and checking for additional content - before merging.

{
throw JsonReaderException.Create(reader, "Additional text found in JSON string after parsing content.");
// Any content encountered here other than a comment will throw in the reader.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As became apparent. There's no way to actually detect reader.TokenType != JsonToken.Comment without catching the exception from the reader itself, and little point since the exception thrown is applicable.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! Looks good to me.

@JamesNK JamesNK merged commit 8956d3c into JamesNK:master Jan 18, 2017
@JonHanna JonHanna deleted the related_1183 branch January 18, 2017 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants