diff --git a/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/SimpleValueReader.java b/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/SimpleValueReader.java index e0a09154..fa6103af 100644 --- a/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/SimpleValueReader.java +++ b/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/SimpleValueReader.java @@ -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 diff --git a/jr-objects/src/test/java/com/fasterxml/jackson/jr/ob/NullHandlingTest.java b/jr-objects/src/test/java/com/fasterxml/jackson/jr/ob/NullHandlingTest.java index 5a4c5a1e..e6299900 100644 --- a/jr-objects/src/test/java/com/fasterxml/jackson/jr/ob/NullHandlingTest.java +++ b/jr-objects/src/test/java/com/fasterxml/jackson/jr/ob/NullHandlingTest.java @@ -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 { @@ -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); + } } diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index ca1e5465..266be02a 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -6,7 +6,7 @@ Tatu Saloranta, tatu.saloranta@iki.fi: author Contributors: -Michael Dombrowski (MikeDombo@github) +Michael Dombrowski (@MikeDombo) * Contributed #80: Case-insensitive property, enum deserialization should be supported @@ -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) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 24b2c905..59d13578 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -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)