Skip to content

Commit

Permalink
Change post #116 to potentially change serialization of `java.nio.fil…
Browse files Browse the repository at this point in the history
…e.Path`
  • Loading branch information
cowtowncoder committed Feb 20, 2024
1 parent 2ebaaf1 commit 66cf5b3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,8 @@ protected String dateToString(Date v) {
* @since 2.17
*/
protected String pathToString(Path value) {
return value.toUri().toString();
// return value.toUri().toString();
return value.toString();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ protected Path _readPath(JsonParser p) throws IOException {
}
String v = p.getValueAsString();
try {
return Paths.get(new URI(v));
// return Paths.get(new URI(v));
return Paths.get(new File(v).toURI());
} catch (Exception e) {
throw new JSONObjectException("Failed to bind `java.nio.file.Path` from value '"+v+"'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ public void testKnownSimpleTypeFile() throws Exception
public void testKnownSimpleTypePath() throws Exception
{
Path p = Paths.get(new URI("file:///foo/bar.txt"));
assertEquals(q("file:///foo/bar.txt"), JSON.std.asString(p));
assertEquals(q("/foo/bar.txt"), JSON.std.asString(p));

assertEquals(a2q("{'path':'file:///foo/bar.txt'}"), JSON.std.asString(new PathWrapper(p)));
assertEquals(a2q("{'path':'/foo/bar.txt'}"), JSON.std.asString(new PathWrapper(p)));
}

public void testSimpleEnumTypes() throws Exception
Expand Down

0 comments on commit 66cf5b3

Please sign in to comment.