-
Notifications
You must be signed in to change notification settings - Fork 4.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
Add setting for leniency on Gson instance. #771
Conversation
This is good. It’s a bit unfortunate that by default |
LGTM. @inder123 any thoughts? |
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); |
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.
Wanna use another example? It’s likely we’ll support top-level primitives.
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.
Yep yep. I was planning on porting the RFC 7159 change to here today anyway.
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.
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.
c5ac860
to
3360c93
Compare
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) { |
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.
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.
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.
Parity with newJsonWriter
and protection against future configuration options being added.
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, that seems reasonable.
Add setting for leniency on Gson instance.
Add setting for leniency on Gson instance.
Add a JsonReader factory (for parity with the JsonWriter one) which provides a configured instance using the Gson settings.