-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Conversation
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this 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."); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that makes sense.
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. |
There was a problem hiding this comment.
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 catch
ing the exception from the reader itself, and little point since the exception thrown is applicable.
There was a problem hiding this comment.
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.
Fix issues similar to #1182 in
JToken
and derived types.Include line information in exception.