File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
spring-boot-project/spring-boot/src
main/java/org/springframework/boot/json
test/java/org/springframework/boot/json Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2012-2024 the original author or authors.
2
+ * Copyright 2012-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
19
19
import java .io .IOException ;
20
20
import java .io .UncheckedIOException ;
21
+ import java .nio .file .Path ;
21
22
import java .util .ArrayDeque ;
22
23
import java .util .Arrays ;
23
24
import java .util .Deque ;
@@ -114,6 +115,10 @@ else if (value instanceof WritableJson writableJson) {
114
115
throw new UncheckedIOException (ex );
115
116
}
116
117
}
118
+ // https://github.com/spring-projects/spring-boot/issues/44502
119
+ else if (value instanceof Path p ) {
120
+ writeArray ((consumer ) -> p .forEach ((element ) -> consumer .accept (element .toString ())));
121
+ }
117
122
else if (value instanceof Iterable <?> iterable ) {
118
123
writeArray (iterable ::forEach );
119
124
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2012-2024 the original author or authors.
2
+ * Copyright 2012-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .boot .json ;
18
18
19
+ import java .nio .file .Path ;
19
20
import java .util .LinkedHashMap ;
20
21
import java .util .LinkedHashSet ;
21
22
import java .util .List ;
@@ -240,6 +241,20 @@ void endWhenNotStartedThrowsException() {
240
241
.isThrownBy (() -> valueWriter .end (Series .ARRAY )));
241
242
}
242
243
244
+ // https://github.com/spring-projects/spring-boot/issues/44502
245
+ @ Test
246
+ void writeJavaNioPathWhenSingleElementShouldNotCauseStackOverflow () {
247
+ assertThat (doWrite ((valueWriter ) -> valueWriter .write (Path .of ("foo" )))).isEqualTo ("""
248
+ ["foo"]""" );
249
+ }
250
+
251
+ // https://github.com/spring-projects/spring-boot/issues/44502
252
+ @ Test
253
+ void writeJavaNioPathShouldNotCauseStackOverflow () {
254
+ assertThat (doWrite ((valueWriter ) -> valueWriter .write (Path .of ("stack/over/flow" )))).isEqualTo ("""
255
+ ["stack","over","flow"]""" );
256
+ }
257
+
243
258
private <V > String write (V value ) {
244
259
return doWrite ((valueWriter ) -> valueWriter .write (value ));
245
260
}
You can’t perform that action at this time.
0 commit comments