Skip to content

Commit

Permalink
Fix #107: accept null for byte[] target
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 10, 2023
1 parent 872c957 commit e275fe3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,13 @@ public Object read(JSONReader reader, JsonParser p) throws IOException
*/

protected byte[] _readBinary(JsonParser p) throws IOException {
// [jackson-jr#107]: should allow null
if (p.hasToken(JsonToken.VALUE_NULL)) {
return null;
}
return p.getBinaryValue();
}

protected int[] _readIntArray(JsonParser p) throws IOException
{
// !!! TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

public class NullHandlingTest extends TestBase
{
static class Bean107 {
public byte[] b = new byte[0];
}

static class StringBean {
public String str = "a";
}

// Test to verify that outputting of nulls is configurable
public void testMapNullEntries() throws Exception
{
Expand All @@ -17,4 +25,21 @@ public void testMapNullEntries() throws Exception
assertEquals("{\"a\":1,\"b\":null}",
JSON.std.with(JSON.Feature.WRITE_NULL_PROPERTIES).asString(map));
}

public void testNullForString() throws Exception
{
assertNull(JSON.std.beanFrom(StringBean.class, "null"));

StringBean bean = JSON.std.beanFrom(StringBean.class, a2q("{'str':null}"));
assertNull(bean.str);
}

// [jackson-jr#107]: nulls should be accepted as byte[]
public void testNullForByteArray() throws Exception
{
assertNull(JSON.std.beanFrom(Bean107.class, "null"));

Bean107 bean = JSON.std.beanFrom(Bean107.class, a2q("{'b':null}"));
assertNull(bean.b);
}
}
11 changes: 8 additions & 3 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Tatu Saloranta, [email protected]: author

Contributors:

Michael Dombrowski (MikeDombo@github)
Michael Dombrowski (@MikeDombo)

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

Jonas Konrad (yawkat@github)
Jonas Konrad (@yawkat)

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

Gerben Oolbekkink (qurben@github)
Gerben Oolbekkink (@github)

* Reported #98: `module-info.java` of `jr-stree` refers to module `com.fasterxml.jackson.jr.ob.api`,
which is not defined
(2.13.5)

Reed Passaretti (@reed53)

* Reported #107: Cannot deserialize `byte[]` from JSON `null` value
(2.15.3)
5 changes: 5 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Modules:
=== Releases ===
------------------------------------------------------------------------

2.15.3 (not yet released)

#107: Cannot deserialize `byte[]` from JSON `null` value
(reported by Reed P)

2.15.2 (30-May-2023)
2.15.1 (16-May-2023)
2.15.0 (23-Apr-2023)
Expand Down

0 comments on commit e275fe3

Please sign in to comment.