Skip to content

Commit 608b5e6

Browse files
authored
Merge pull request #108 from FasterXML/tatu/2.15/107-null-for-bytearray
Fix #107: accept `null` for `byte[]` target
2 parents 872c957 + e275fe3 commit 608b5e6

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,13 @@ public Object read(JSONReader reader, JsonParser p) throws IOException
239239
*/
240240

241241
protected byte[] _readBinary(JsonParser p) throws IOException {
242+
// [jackson-jr#107]: should allow null
243+
if (p.hasToken(JsonToken.VALUE_NULL)) {
244+
return null;
245+
}
242246
return p.getBinaryValue();
243247
}
244-
248+
245249
protected int[] _readIntArray(JsonParser p) throws IOException
246250
{
247251
// !!! TODO

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
public class NullHandlingTest extends TestBase
77
{
8+
static class Bean107 {
9+
public byte[] b = new byte[0];
10+
}
11+
12+
static class StringBean {
13+
public String str = "a";
14+
}
15+
816
// Test to verify that outputting of nulls is configurable
917
public void testMapNullEntries() throws Exception
1018
{
@@ -17,4 +25,21 @@ public void testMapNullEntries() throws Exception
1725
assertEquals("{\"a\":1,\"b\":null}",
1826
JSON.std.with(JSON.Feature.WRITE_NULL_PROPERTIES).asString(map));
1927
}
28+
29+
public void testNullForString() throws Exception
30+
{
31+
assertNull(JSON.std.beanFrom(StringBean.class, "null"));
32+
33+
StringBean bean = JSON.std.beanFrom(StringBean.class, a2q("{'str':null}"));
34+
assertNull(bean.str);
35+
}
36+
37+
// [jackson-jr#107]: nulls should be accepted as byte[]
38+
public void testNullForByteArray() throws Exception
39+
{
40+
assertNull(JSON.std.beanFrom(Bean107.class, "null"));
41+
42+
Bean107 bean = JSON.std.beanFrom(Bean107.class, a2q("{'b':null}"));
43+
assertNull(bean.b);
44+
}
2045
}

release-notes/CREDITS-2.x

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Tatu Saloranta, [email protected]: author
66

77
Contributors:
88

9-
Michael Dombrowski (MikeDombo@github)
9+
Michael Dombrowski (@MikeDombo)
1010

1111
* Contributed #80: Case-insensitive property, enum deserialization
1212
should be supported
@@ -18,13 +18,18 @@ Michael Dombrowski (MikeDombo@github)
1818
* Contributed #84: Public static fields are included in serialized output
1919
(2.13.0)
2020

21-
Jonas Konrad (yawkat@github)
21+
Jonas Konrad (@yawkat)
2222

2323
* Suggested #88: Make `jr-stree` dependency to `jr-objects` optional
2424
(2.13.0)
2525

26-
Gerben Oolbekkink (qurben@github)
26+
Gerben Oolbekkink (@github)
2727

2828
* Reported #98: `module-info.java` of `jr-stree` refers to module `com.fasterxml.jackson.jr.ob.api`,
2929
which is not defined
3030
(2.13.5)
31+
32+
Reed Passaretti (@reed53)
33+
34+
* Reported #107: Cannot deserialize `byte[]` from JSON `null` value
35+
(2.15.3)

release-notes/VERSION-2.x

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Modules:
1111
=== Releases ===
1212
------------------------------------------------------------------------
1313

14+
2.15.3 (not yet released)
15+
16+
#107: Cannot deserialize `byte[]` from JSON `null` value
17+
(reported by Reed P)
18+
1419
2.15.2 (30-May-2023)
1520
2.15.1 (16-May-2023)
1621
2.15.0 (23-Apr-2023)

0 commit comments

Comments
 (0)