Skip to content

Commit b86ef5a

Browse files
authored
Merge pull request #119 from FasterXML/tatu/2.17/116-chagen-path-serialization
Change post #116 to potentially change serialization of `java.nio.file.Path`
2 parents 2ebaaf1 + daf612d commit b86ef5a

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/JSONWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ protected String dateToString(Date v) {
789789
* @since 2.17
790790
*/
791791
protected String pathToString(Path value) {
792-
return value.toUri().toString();
792+
return value.toString();
793793
}
794794

795795
/*

jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/SimpleValueReader.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,15 @@ public Object read(JSONReader reader, JsonParser p) throws IOException
152152
return p.getValueAsLong();
153153

154154
case SER_NUMBER_BIG_DECIMAL:
155+
if (p.hasToken(JsonToken.VALUE_NULL)) {
156+
return null;
157+
}
155158
return p.getDecimalValue();
156159

157160
case SER_NUMBER_BIG_INTEGER:
161+
if (p.hasToken(JsonToken.VALUE_NULL)) {
162+
return null;
163+
}
158164
return p.getBigIntegerValue();
159165

160166
// Other scalar types:
@@ -278,7 +284,7 @@ protected Path _readPath(JsonParser p) throws IOException {
278284
}
279285
String v = p.getValueAsString();
280286
try {
281-
return Paths.get(new URI(v));
287+
return Paths.get(v);
282288
} catch (Exception e) {
283289
throw new JSONObjectException("Failed to bind `java.nio.file.Path` from value '"+v+"'");
284290
}

jr-objects/src/test/java/com/fasterxml/jackson/jr/ob/ReadSimpleTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ public void testMiscScalarFail() throws Exception {
208208
/**********************************************************************
209209
*/
210210

211-
// 07-Jul-2020, tatu: Should be able to check but as of 2.11 same reader used
212-
// for wrapper and primitives.
213-
/*
214211
public void testNullForMiscNumbers() throws Exception {
215212
assertNull(JSON.std.beanFrom(Integer.class," null "));
216213
assertNull(JSON.std.beanFrom(Long.class," null "));
@@ -219,7 +216,6 @@ public void testNullForMiscNumbers() throws Exception {
219216
assertNull(JSON.std.beanFrom(BigInteger.class," null "));
220217
assertNull(JSON.std.beanFrom(BigDecimal.class," null "));
221218
}
222-
*/
223219

224220
public void testNullForMiscScalars() throws Exception {
225221
assertNull(JSON.std.beanFrom(Date.class," null "));

jr-objects/src/test/java/com/fasterxml/jackson/jr/ob/WriteSimpleTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ public void testKnownSimpleTypeFile() throws Exception
127127
public void testKnownSimpleTypePath() throws Exception
128128
{
129129
Path p = Paths.get(new URI("file:///foo/bar.txt"));
130-
assertEquals(q("file:///foo/bar.txt"), JSON.std.asString(p));
130+
assertEquals(q("/foo/bar.txt"), JSON.std.asString(p));
131131

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

135135
public void testSimpleEnumTypes() throws Exception

0 commit comments

Comments
 (0)