Skip to content

Commit 7c9e7c1

Browse files
authored
Fix #4450: deserialize QName "" as empty, not null (#4468)
1 parent 9d31ec7 commit 7c9e7c1

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Project: jackson-databind
2020
String ".05": not a valid representation
2121
(reported by @EAlf91)
2222
(fix by @pjfanning)
23+
#4450: Empty QName deserialized as `null`
24+
(reported by @winfriedgerlach)
2325

2426
2.17.0 (12-Mar-2024)
2527

src/main/java/com/fasterxml/jackson/databind/deser/std/FromStringDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ protected Object _deserializeFromEmptyString(DeserializationContext ctxt) throws
256256
if (act == CoercionAction.AsEmpty) {
257257
return getEmptyValue(ctxt);
258258
}
259-
// 09-Jun-2020, tatu: semantics for `TryConvert` are bit interesting due to
259+
// 09-Jun-2020, tatu: semantics for `TryConvert` are a bit interesting due to
260260
// historical reasons
261261
return _deserializeFromEmptyStringDefault(ctxt);
262262
}

src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLDeserializers.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
*/
2020
public class CoreXMLDeserializers extends Deserializers.Base
2121
{
22+
protected final static QName EMPTY_QNAME = QName.valueOf("");
23+
2224
/**
2325
* Data type factories are thread-safe after instantiation (and
24-
* configuration, if any); and since instantion (esp. implementation
26+
* configuration, if any); and since instantiation (esp. implementation
2527
* introspection) can be expensive we better reuse the instance.
2628
*/
2729
final static DatatypeFactory _dataTypeFactory;
@@ -125,6 +127,14 @@ protected Object _deserialize(String value, DeserializationContext ctxt)
125127
throw new IllegalStateException();
126128
}
127129

130+
@Override
131+
protected Object _deserializeFromEmptyString(DeserializationContext ctxt) throws IOException {
132+
if (_kind == TYPE_QNAME) {
133+
return EMPTY_QNAME;
134+
}
135+
return super._deserializeFromEmptyString(ctxt);
136+
}
137+
128138
protected XMLGregorianCalendar _gregorianFromDate(DeserializationContext ctxt,
129139
Date d)
130140
{

src/test/java/com/fasterxml/jackson/databind/ext/MiscJavaXMLTypesReadWriteTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ public void testQNameDeser() throws Exception
115115
String qstr = qn.toString();
116116
assertEquals(qn, MAPPER.readValue(q(qstr), QName.class),
117117
"Should deserialize to equal QName (exp serialization: '"+qstr+"')");
118+
119+
// [databind#4450]
120+
qn = MAPPER.readValue(q(""), QName.class);
121+
assertNotNull(qn);
122+
assertEquals("", qn.getLocalPart());
118123
}
119124

120125
@Test

0 commit comments

Comments
 (0)