Skip to content

Commit 93e38d1

Browse files
committed
Fix #53
1 parent f043727 commit 93e38d1

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,27 +1040,27 @@ protected JsonParser _parser(Object source) throws IOException, JSONObjectExcept
10401040
if (type == String.class) {
10411041
return f.createParser((String) source);
10421042
}
1043+
if (type == byte[].class) {
1044+
return f.createParser((byte[]) source);
1045+
}
10431046
if (source instanceof InputStream) {
10441047
return f.createParser((InputStream) source);
10451048
}
10461049
if (source instanceof Reader) {
10471050
return f.createParser((Reader) source);
10481051
}
1049-
if (type == byte[].class) {
1050-
return f.createParser((byte[]) source);
1051-
}
10521052
if (source instanceof URL) {
10531053
return f.createParser((URL) source);
10541054
}
10551055
if (type == char[].class) {
10561056
return f.createParser(new CharArrayReader((char[]) source));
10571057
}
1058+
if (source instanceof File) {
1059+
return f.createParser((File) source);
1060+
}
10581061
if (source instanceof CharSequence) {
10591062
return f.createParser(((CharSequence) source).toString());
10601063
}
1061-
if (source instanceof JsonParser) { // should never be called with this
1062-
throw new IllegalStateException();
1063-
}
10641064
throw new JSONObjectException("Can not use Source of type "+source.getClass().getName()
10651065
+" as input (use an InputStream, Reader, String, byte[], File or URL");
10661066
}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
package com.fasterxml.jackson.jr.ob;
22

3+
import java.io.*;
4+
35
public class RoundtripTest extends TestBase
46
{
57
public void testSimple() throws Exception
68
{
79
MediaItem input = buildItem();
810
String json = JSON.std.asString(input);
9-
MediaItem item = JSON.std.beanFrom(MediaItem.class, json);
10-
String json2 = JSON.std.asString(item);
1111

12-
assertEquals(json, json2);
12+
// Let's exercise multiple styles of input sources
13+
14+
assertEquals(json, _readWrite(json));
15+
byte[] b = json.getBytes("UTF-8");
16+
assertEquals(json, _readWrite(b));
17+
assertEquals(json, _readWrite(new ByteArrayInputStream(b)));
18+
assertEquals(json, _readWrite(new StringReader(json)));
19+
assertEquals(json, _readWrite(json.toCharArray()));
20+
}
21+
22+
private String _readWrite(Object json) throws Exception
23+
{
24+
MediaItem item = JSON.std.beanFrom(MediaItem.class, json);
25+
return JSON.std.asString(item);
1326
}
1427

1528
private MediaItem buildItem() {

release-notes/VERSION

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Project: jackson-jr
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.8.10 (not yet released)
8+
9+
#53: `java.io.File` is not a valid source for anyFrom()/mapFrom()
10+
(reported by CoreyTeffetalor@github)
11+
712
2.8.9 (12-Jun-2017)
813

914
#50: Duplicate key detection does not work

0 commit comments

Comments
 (0)