|
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; |
32 | 33 | import java.io.EOFException;
|
33 | 34 | import java.io.IOException;
|
34 | 35 | import java.io.Reader;
|
35 | 36 | import java.io.StringReader;
|
| 37 | +import java.io.StringWriter; |
36 | 38 | import java.util.Arrays;
|
| 39 | +import java.util.Iterator; |
| 40 | +import java.util.stream.Stream; |
37 | 41 | import org.junit.Ignore;
|
38 | 42 | import org.junit.Test;
|
39 | 43 |
|
@@ -2170,6 +2174,27 @@ private static void assertDocument(String document, Object... expectations) thro
|
2170 | 2174 | }
|
2171 | 2175 | }
|
2172 | 2176 |
|
| 2177 | + @Test |
| 2178 | + public void testJsonReaderWithStrictnessSetToLenientAndNullValue() throws IOException { |
| 2179 | + Iterator<String> iterator = Stream.of(null, "value1", "value2").iterator(); |
| 2180 | + StringWriter str = new StringWriter(); |
| 2181 | + |
| 2182 | + try (JsonWriter writer = new JsonWriter(str)) { |
| 2183 | + writer.setStrictness(Strictness.LENIENT); |
| 2184 | + while (iterator.hasNext()) { |
| 2185 | + TypeAdapters.STRING.write(writer, iterator.next()); |
| 2186 | + } |
| 2187 | + writer.flush(); |
| 2188 | + } |
| 2189 | + |
| 2190 | + JsonReader reader = new JsonReader(new StringReader(str.toString())); |
| 2191 | + reader.setStrictness(Strictness.LENIENT); |
| 2192 | + |
| 2193 | + assertThat(TypeAdapters.STRING.read(reader)).isEqualTo("null"); |
| 2194 | + assertThat(TypeAdapters.STRING.read(reader)).isEqualTo("value1"); |
| 2195 | + assertThat(TypeAdapters.STRING.read(reader)).isEqualTo("value2"); |
| 2196 | + } |
| 2197 | + |
2173 | 2198 | /** Returns a reader that returns one character at a time. */
|
2174 | 2199 | private static Reader reader(String s) {
|
2175 | 2200 | /* if (true) */ return new StringReader(s);
|
|
0 commit comments