-
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
JsonReader with strictness set to LENIENT, #2769
Comments
Not sure if this something which can be solved for Maybe the underlying issue here is how Is your main use case to write multiple top-level values? StringWriter str = new StringWriter();
while (iterator.hasNext()) {
String value = iterator.next();
JsonWriter writer = new JsonWriter(str);
writer.setStrictness(Strictness.STRICT);
TypeAdapters.STRING.write(writer, value);
writer.flush();
str.append('\n');
} |
Actualy, fixing the thing on JsonReader side only is impossible i think, some cases will remain impossible to solve. I like your workaround,
Edit : Actualy using a single JsonReader with Strictness.LENIENT corretly handle multiple top level values separate by '\n' |
Gson version
2.11.0
Java / Android version
any version
Used tools
none
Description
With a JsonReader with strictness = LENIENT, all values after a null are read as a single string begining by "null".
Expected behavior
Values are correctly read.
Reproduction steps
With
stream = Stream.of("value1", "value2");
-> OKWith
stream = Stream.of("value1", null);
, -> OK(the printed null is really a null value, not "null" String -> OK)
With
stream = Stream.of(null, "value1");
-> KOWith
stream = Stream.of(null, "value1", "value2");
-> KO (and so on)With
stream = Stream.of("value1", null, "value2");
-> KOWith
stream = Stream.of("value1", null, "value2", "value3");
-> KO (and so on)Same behavior happens with other json primitive type but not with json object or json array.
Save behavior happens in previous gson version with
#setLenient(true);
.The text was updated successfully, but these errors were encountered: