Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Marcono1234
Copy link
Contributor

@Marcono1234 Marcono1234 commented May 22, 2022

Fixes #1720
Resolves #1923

Relates to: #372, #763, #1208, #1609

Improves the documentation regarding lenient mode and trailing data handling. The current Gson behavior is still not ideal, but now at least the documentation (hopefully) matches the actual behavior.

* read is strict. Create a {@link JsonReader#setLenient(boolean) lenient}
* {@code JsonReader} and call {@link #read(JsonReader)} for lenient reading.
*
* <p>No exception is thrown if the JSON data has multiple top-level JSON elements,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This behavior is probably rather questionable though...

* prefix</a>, <code>")]}'\n"</code>.
* <li>Streams that include multiple top-level values. With strict parsing,
* each stream must contain exactly one top-level value.
* <li>Top-level values of any type. With strict parsing, the top-level
Copy link
Contributor Author

@Marcono1234 Marcono1234 May 22, 2022

Choose a reason for hiding this comment

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

This and the changes below in this file are based on #1609 and the comments there.

This specific sentence was outdated because Gson already supports top-level values of other types, even in strict mode.

* <li>Name/value pairs separated by {@code ;} instead of {@code ,}.
* </ul>
*
* <p>Note: Even in strict mode there are slight derivations from the JSON
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe this should clarify that these derivations are not guaranteed behavior and might change in the future?

@eamonnmcmanus
Copy link
Member

Thanks for doing this! I'm merging as-is, but feel free to convert some of the open questions into other PRs or new issues.

@eamonnmcmanus eamonnmcmanus merged commit cbc0af8 into google:master Jun 28, 2022
@Marcono1234 Marcono1234 deleted the marcono1234/lenient-doc-improvements branch June 29, 2022 19:37
@Marcono1234
Copy link
Contributor Author

Thanks for merging this!

feel free to convert some of the open questions into other PRs or new issues

The main open problem is probably the missing end of document check for the TypeAdapter methods, but changing that would be backward incompatible. At least this behavior is now documented, so I don't think any further action is necessary at the moment.

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.

Mistake on Javadoc method description (?) Gson.assertFullConsumption should throw JsonSyntaxException if JSON was not fully consumed

2 participants