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

Unable to verify lenient parsing. #1079

Closed
johan-roets opened this issue May 17, 2017 · 2 comments
Closed

Unable to verify lenient parsing. #1079

johan-roets opened this issue May 17, 2017 · 2 comments

Comments

@johan-roets
Copy link

johan-roets commented May 17, 2017

Hi,

I'm trying to write some unit tests on our code to confirm that we are using lenient parsing. I can add some non lenient json and everything parses correctly. The issue is that everything still parses correctly even when I use the default, non lenient parsing?

//both of these work:
String json = "{ _id => a1b2; id2 = 'a1b3'; arr=[1,2;3;4] }";
JsonElement jsonElement = new GsonBuilder().setLenient().create().fromJson(json, JsonElement.class);
JsonElement jsonElement2 = new GsonBuilder().create().fromJson(json, JsonElement.class);

//both of these fail:
json = " _id : a1b2";
new GsonBuilder().setLenient().create().fromJson(json, JsonElement.class);
new GsonBuilder().create().fromJson(json, JsonElement.class);
@johan-roets
Copy link
Author

Realise this might be a duplicate of
#372 and #499

The Gson documentation is misleading. If Gson will always be lenient the documentation should state so.

Also, found inconsistencies in the code:
JsonParser.parse line 59 and 60. The parse method will always use lenient on line 59, but right after that the peek method reverts back to handling according to the lenient flag.

If you want to be lenient always, remove the setLenient and related documentation and just make the lenient flag final and true.

@Marcono1234
Copy link
Collaborator

Probably resolved (but not really fixed) by #2122

@eamonnmcmanus eamonnmcmanus closed this as not planned Won't fix, can't repro, duplicate, stale Jul 29, 2022
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

No branches or pull requests

3 participants