From 86fa6622ee0f874f1063252611219588e72ea243 Mon Sep 17 00:00:00 2001 From: xavi_torrens Date: Thu, 3 Mar 2016 21:05:30 +0100 Subject: [PATCH 1/2] According to [databind#742], we shouldn't throw an exception if the value of the property is null --- .../jackson/databind/deser/std/StringDeserializer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/StringDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/StringDeserializer.java index c420536dd1..c3d49b5339 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/std/StringDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/StringDeserializer.java @@ -55,7 +55,8 @@ public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx } // allow coercions for other scalar types String text = p.getValueAsString(); - if (text != null) { + // According to [databind#742], we shouldn't throw an exception if the value of the property is null + if (text != null || JsonToken.VALUE_NULL.equals(p.getCurrentToken())) { return text; } throw ctxt.mappingException(_valueClass, p.getCurrentToken()); From 906c9149fe892098e4f57aa06445627a55990414 Mon Sep 17 00:00:00 2001 From: xavi_torrens Date: Wed, 9 Mar 2016 17:38:24 +0100 Subject: [PATCH 2/2] made a test for reproduce the case described in databind#1150 (changes in StringDeserializer class). --- .../deser/std/StringDeserializer.java | 2 +- .../objectid/TestObjectIdDeserialization.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/StringDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/StringDeserializer.java index c3d49b5339..f8e0d88155 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/std/StringDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/StringDeserializer.java @@ -55,7 +55,7 @@ public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx } // allow coercions for other scalar types String text = p.getValueAsString(); - // According to [databind#742], we shouldn't throw an exception if the value of the property is null + // According to [databind#742], StringDeserializer shouldn't throw an exception if the value of the property is null if (text != null || JsonToken.VALUE_NULL.equals(p.getCurrentToken())) { return text; } diff --git a/src/test/java/com/fasterxml/jackson/databind/objectid/TestObjectIdDeserialization.java b/src/test/java/com/fasterxml/jackson/databind/objectid/TestObjectIdDeserialization.java index 2db9bdc610..cebd83c5d8 100644 --- a/src/test/java/com/fasterxml/jackson/databind/objectid/TestObjectIdDeserialization.java +++ b/src/test/java/com/fasterxml/jackson/databind/objectid/TestObjectIdDeserialization.java @@ -466,4 +466,31 @@ public void testNullObjectId() throws Exception assertNotNull(value); assertEquals(3, value.value); } + + //for databind#1150 + @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id") + static class IdentifiableStringId + { + public String id; + public int value; + + public Identifiable next; + + public IdentifiableStringId() { this(0); } + public IdentifiableStringId(int v) { + value = v; + } + } + + public void testNullStringPropertyId() throws Exception + { + + + IdentifiableStringId value = MAPPER.readValue + (aposToQuotes("{'value':3, 'next':null, 'id':null}"), IdentifiableStringId.class); + assertNotNull(value); + assertEquals(3, value.value); + } + + }