File tree 2 files changed +16
-1
lines changed
spring-boot-project/spring-boot/src
main/java/org/springframework/boot/json
test/java/org/springframework/boot/json
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 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,9 @@ else if (value instanceof WritableJson writableJson) {
114
115
throw new UncheckedIOException (ex );
115
116
}
116
117
}
118
+ else if (value instanceof Path p ) {
119
+ writeString (p .toString ());
120
+ }
117
121
else if (value instanceof Iterable <?> iterable ) {
118
122
writeArray (iterable ::forEach );
119
123
}
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,16 @@ void endWhenNotStartedThrowsException() {
240
241
.isThrownBy (() -> valueWriter .end (Series .ARRAY )));
241
242
}
242
243
244
+ @ Test // gh-44502
245
+ void writeJavaNioPathWhenSingleElementShouldBeSerializedAsString () {
246
+ assertThat (doWrite ((valueWriter ) -> valueWriter .write (Path .of ("a" )))).isEqualTo (quoted ("a" ));
247
+ }
248
+
249
+ @ Test // gh-44502
250
+ void writeJavaNioPathShouldBeSerializedAsString () {
251
+ assertThat (doWrite ((valueWriter ) -> valueWriter .write (Path .of ("a/b/c" )))).isEqualTo (quoted ("a\\ /b\\ /c" ));
252
+ }
253
+
243
254
private <V > String write (V value ) {
244
255
return doWrite ((valueWriter ) -> valueWriter .write (value ));
245
256
}
You can’t perform that action at this time.
0 commit comments