File tree Expand file tree Collapse 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 Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 11/*
2- * Copyright 2012-2024 the original author or authors.
2+ * Copyright 2012-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1818
1919import java .io .IOException ;
2020import java .io .UncheckedIOException ;
21+ import java .nio .file .Path ;
2122import java .util .ArrayDeque ;
2223import java .util .Arrays ;
2324import java .util .Deque ;
@@ -114,6 +115,10 @@ else if (value instanceof WritableJson writableJson) {
114115 throw new UncheckedIOException (ex );
115116 }
116117 }
118+ // https://github.com/spring-projects/spring-boot/issues/44502
119+ else if (value instanceof Path p ) {
120+ writeString (p .toString ());
121+ }
117122 else if (value instanceof Iterable <?> iterable ) {
118123 writeArray (iterable ::forEach );
119124 }
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2012-2024 the original author or authors.
2+ * Copyright 2012-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1616
1717package org .springframework .boot .json ;
1818
19+ import java .nio .file .Path ;
1920import java .util .LinkedHashMap ;
2021import java .util .LinkedHashSet ;
2122import java .util .List ;
@@ -240,6 +241,18 @@ void endWhenNotStartedThrowsException() {
240241 .isThrownBy (() -> valueWriter .end (Series .ARRAY )));
241242 }
242243
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+
243256 private <V > String write (V value ) {
244257 return doWrite ((valueWriter ) -> valueWriter .write (value ));
245258 }
You can’t perform that action at this time.
0 commit comments