File tree Expand file tree Collapse file tree 2 files changed +17
-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 +17
-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,9 @@ else if (value instanceof WritableJson writableJson) {
114115 throw new UncheckedIOException (ex );
115116 }
116117 }
118+ else if (value instanceof Path p ) {
119+ writeString (p .toString ());
120+ }
117121 else if (value instanceof Iterable <?> iterable ) {
118122 writeArray (iterable ::forEach );
119123 }
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,16 @@ void endWhenNotStartedThrowsException() {
240241 .isThrownBy (() -> valueWriter .end (Series .ARRAY )));
241242 }
242243
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+
243254 private <V > String write (V value ) {
244255 return doWrite ((valueWriter ) -> valueWriter .write (value ));
245256 }
You can’t perform that action at this time.
0 commit comments