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

Add setting for leniency on Gson instance. #771

Merged
merged 1 commit into from
Jan 18, 2016
Merged

Conversation

JakeWharton
Copy link
Contributor

Add a JsonReader factory (for parity with the JsonWriter one) which provides a configured instance using the Gson settings.

@swankjesse
Copy link
Collaborator

This is good. It’s a bit unfortunate that by default Gson is actually lenient in some cases and not-lenient in others. Oh well.

@swankjesse
Copy link
Collaborator

LGTM. @inder123 any thoughts?

@JakeWharton
Copy link
Contributor Author

It’s a bit unfortunate that by default Gson is actually lenient in some cases and not-lenient in others. Oh well.

Agree! Too late to change. Just trying to make the best of that unfortunate situation.

}

public void testLenientFromJson() {
String json = gson.fromJson("\"Hello\"", String.class);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wanna use another example? It’s likely we’ll support top-level primitives.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep yep. I was planning on porting the RFC 7159 change to here today anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use comments and single-quote string in otherwise valid JSON.

Add a JsonReader factory (for parity with the JsonWriter one) which provides a configured instance using the Gson settings.
@swankjesse
Copy link
Collaborator

LGTM!

@@ -705,6 +714,15 @@ public JsonWriter newJsonWriter(Writer writer) throws IOException {
}

/**
* Returns a new JSON writer configured for the settings on this Gson instance.
*/
public JsonReader newJsonReader(Reader reader) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The method body seems fairly straightforward. Why can't the developer do this themselves?
We could just expose an isLenient() method instead. That will have uses beyond the low-level streaming. For example, a TypeAdapterFactory can then use Gson.isLenient() to make decisions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Parity with newJsonWriter and protection against future configuration options being added.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, that seems reasonable.

inder123 added a commit that referenced this pull request Jan 18, 2016
Add setting for leniency on Gson instance.
@inder123 inder123 merged commit 2ab776b into master Jan 18, 2016
@inder123 inder123 deleted the jw/global-leniency branch January 18, 2016 19:03
@inder123 inder123 self-assigned this Jan 18, 2016
sebasjm pushed a commit to sebasjm/gson that referenced this pull request Mar 11, 2018
Add setting for leniency on Gson instance.
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.

3 participants