|
18 | 18 |
|
19 | 19 | import java.io.File;
|
20 | 20 | import java.nio.file.Path;
|
| 21 | +import java.util.ArrayList; |
21 | 22 | import java.util.LinkedHashMap;
|
22 | 23 | import java.util.LinkedHashSet;
|
23 | 24 | import java.util.List;
|
@@ -253,6 +254,36 @@ void writeJavaNioPathShouldBeSerializedAsString() {
|
253 | 254 | .isEqualTo(quoted("a\\%1$sb\\%1$sc".formatted(File.separator)));
|
254 | 255 | }
|
255 | 256 |
|
| 257 | + @Test |
| 258 | + void illegalStateExceptionShouldBeThrownWhenCollectionExceededNestingDepth() { |
| 259 | + JsonValueWriter writer = new JsonValueWriter(new StringBuilder(), 128); |
| 260 | + List<Object> list = new ArrayList<>(); |
| 261 | + list.add(list); |
| 262 | + assertThatIllegalStateException().isThrownBy(() -> writer.write(list)) |
| 263 | + .withMessageStartingWith( |
| 264 | + "JSON nesting depth (129) exceeds maximum depth of 128 (current path: [0][0][0][0][0][0][0][0][0][0][0][0]"); |
| 265 | + } |
| 266 | + |
| 267 | + @Test |
| 268 | + void illegalStateExceptionShouldBeThrownWhenMapExceededNestingDepth() { |
| 269 | + JsonValueWriter writer = new JsonValueWriter(new StringBuilder(), 128); |
| 270 | + Map<String, Object> map = new LinkedHashMap<>(); |
| 271 | + map.put("foo", Map.of("bar", map)); |
| 272 | + assertThatIllegalStateException().isThrownBy(() -> writer.write(map)) |
| 273 | + .withMessageStartingWith( |
| 274 | + "JSON nesting depth (129) exceeds maximum depth of 128 (current path: foo.bar.foo.bar.foo.bar.foo"); |
| 275 | + } |
| 276 | + |
| 277 | + @Test |
| 278 | + void illegalStateExceptionShouldBeThrownWhenIterableExceededNestingDepth() { |
| 279 | + JsonValueWriter writer = new JsonValueWriter(new StringBuilder(), 128); |
| 280 | + List<Object> list = new ArrayList<>(); |
| 281 | + list.add(list); |
| 282 | + assertThatIllegalStateException().isThrownBy(() -> writer.write((Iterable<Object>) list::iterator)) |
| 283 | + .withMessageStartingWith( |
| 284 | + "JSON nesting depth (129) exceeds maximum depth of 128 (current path: [0][0][0][0][0][0][0][0][0][0][0][0]"); |
| 285 | + } |
| 286 | + |
256 | 287 | private <V> String write(V value) {
|
257 | 288 | return doWrite((valueWriter) -> valueWriter.write(value));
|
258 | 289 | }
|
|
0 commit comments