File tree 2 files changed +20
-2
lines changed
spring-boot-project/spring-boot/src
main/java/org/springframework/boot/json
test/java/org/springframework/boot/json
2 files changed +20
-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
+ writeString (p .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,18 @@ 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 writeJavaNioPathWhenSingleElementShouldBeSerializedAsString () {
247
+ assertThat (doWrite ((valueWriter ) -> valueWriter .write (Path .of ("overflow" )))).isEqualTo (quoted ("overflow" ));
248
+ }
249
+
250
+ @ Test
251
+ void writeJavaNioPathShouldShouldBeSerializedAsString () {
252
+ assertThat (doWrite ((valueWriter ) -> valueWriter .write (Path .of ("stack/overflow/error" ))))
253
+ .isEqualTo (quoted ("stack\\ /overflow\\ /error" ));
254
+ }
255
+
243
256
private <V > String write (V value ) {
244
257
return doWrite ((valueWriter ) -> valueWriter .write (value ));
245
258
}
You can’t perform that action at this time.
0 commit comments