File tree 2 files changed +28
-0
lines changed
main/java/com/google/gson/stream
test/java/com/google/gson/stream
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -1172,6 +1172,7 @@ private String nextUnquotedValue() throws IOException {
1172
1172
while (true ) {
1173
1173
for (; pos + i < limit ; i ++) {
1174
1174
switch (buffer [pos + i ]) {
1175
+ case '"' :
1175
1176
case '/' :
1176
1177
case '\\' :
1177
1178
case ';' :
Original file line number Diff line number Diff line change 29
29
import static org .junit .Assert .assertThrows ;
30
30
31
31
import com .google .gson .Strictness ;
32
+ import com .google .gson .internal .bind .TypeAdapters ;
33
+
32
34
import java .io .EOFException ;
33
35
import java .io .IOException ;
34
36
import java .io .Reader ;
35
37
import java .io .StringReader ;
38
+ import java .io .StringWriter ;
36
39
import java .util .Arrays ;
40
+ import java .util .Iterator ;
41
+ import java .util .stream .Stream ;
42
+
37
43
import org .junit .Ignore ;
38
44
import org .junit .Test ;
39
45
@@ -2189,4 +2195,25 @@ private static Reader reader(String s) {
2189
2195
}
2190
2196
}; */
2191
2197
}
2198
+
2199
+ @ Test
2200
+ public void testJsonReaderWithStrictnessSetToLenientAndNullValue () throws IOException {
2201
+ Iterator <String > iterator = Stream .of (null , "value1" , "value2" ).iterator ();
2202
+ StringWriter str = new StringWriter ();
2203
+
2204
+ try (JsonWriter writer = new JsonWriter (str )) {
2205
+ writer .setStrictness (Strictness .LENIENT );
2206
+ while (iterator .hasNext ()) {
2207
+ TypeAdapters .STRING .write (writer , iterator .next ());
2208
+ }
2209
+ writer .flush ();
2210
+ }
2211
+
2212
+ JsonReader reader = new JsonReader (new StringReader (str .toString ()));
2213
+ reader .setStrictness (Strictness .LENIENT );
2214
+
2215
+ assertThat (TypeAdapters .STRING .read (reader )).isEqualTo ("null" );
2216
+ assertThat (TypeAdapters .STRING .read (reader )).isEqualTo ("value1" );
2217
+ assertThat (TypeAdapters .STRING .read (reader )).isEqualTo ("value2" );
2218
+ }
2192
2219
}
You can’t perform that action at this time.
0 commit comments