Repository navigation
Open
Labels
Description
Bug description
See FasterXML/jackson-databind#4771: jackson QName (de)serialization ignores prefix.
Environment
Spring Batch 5.1.2, JDK 21
Steps to reproduce
@Test
void qname() throws Exception {
Jackson2ExecutionContextStringSerializer serializer = new Jackson2ExecutionContextStringSerializer();
ExecutionContext context = new ExecutionContext();
QName qname = new QName("http://namespace", "test", "p");
context.put("qname", qname);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
serializer.serialize(new HashMap<>(context.toMap()), outputStream);
LOGGER.info(outputStream.toString(StandardCharsets.UTF_8));
// <- {"@class":"java.util.HashMap","qname":["javax.xml.namespace.QName","{http://namespace}test"]}
Map<String, Object> result = serializer.deserializeFromByteArray(outputStream.toByteArray());
QName value = (QName) result.get("qname");
assertThat(value.getLocalPart()).isEqualTo(qname.getLocalPart());
assertThat(value.getNamespaceURI()).isEqualTo(qname.getNamespaceURI());
assertThat(value.getPrefix()).isEqualTo(qname.getPrefix()); // <- fails
}Expected behavior
QName prefix is preserved in context (de)serialization roundtrip.
Spring Batch StaxEventItemWriter depends on QName prefix being preserved correctly:
Lines 796 to 799 in fc1f3fc
| if (!unclosedHeaderCallbackElements.isEmpty()) { | |
| executionContext.put(getExecutionContextKey(UNCLOSED_HEADER_CALLBACK_ELEMENTS_NAME), | |
| unclosedHeaderCallbackElements); | |
| } |
Activity
jjh75607 commentedon Aug 26, 2026
Some findings, since the situation has changed since this was reported.
The cause for
Jackson2ExecutionContextStringSerializerturns out to sit upstream rather than here. #4771 was resolved in Jackson 2.19 as an opt-in object form, so the fix would be to enableJsonFormat.Shape.OBJECTforQName. But this class writes type idsAs.PROPERTY(Jackson2ExecutionContextStringSerializer.java:272), and Jackson then never enters its QName object branch, silently returning a corrupted value. I have reported that as FasterXML/jackson-databind#6175. The class is deprecated for removal in 7.0 in any case.JacksonExecutionContextStringSerializeris a different matter. It uses wrapper-array type ids, which are unaffected, sowithConfigOverride(QName.class, c -> c.setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.OBJECT)))preserves the prefix. Verified onmain. It needs #5502 first, which currently rejectsQNameoutright.The stored format stays compatible either way. I checked both directions on
main: the new config reads old string-form rows, and the old config reads new object-form rows with the prefix intact. The read path branches on the token it sees.A pull request with that one-line change will follow once #5502 is in, since it depends on
QNamebeing accepted there first.fmbenhassine commentedon Oct 31, 2026
@jpraet Thank you for raising this, it is a valid issue.
While #5529 fixes the issue in
JacksonExecutionContextStringSerializer(Jackson 3 based), porting it toJackson2ExecutionContextStringSerializerrequires more than the object-format configuration change. Although our Jackson 2 versions include support forQNameobject formatting, the serializer’sAs.PROPERTYtype handling encounters FasterXML/jackson-databind#6175. The fix for FasterXML/jackson-databind#6175 has not been backported to Jackson 2, so that port is currently blocked.Given that the Jackson 2-based serializer is deprecated for removal, it's unlikely that we continue spending effort maintaining it (or wait for Jackson to back port their fix to 2.x). Do you still use
Jackson2ExecutionContextStringSerializer?@jjh75607 Thanks for the investigation and for PR #5529! It fixes the prefix loss in
JacksonExecutionContextStringSerializer, including malformed XML produced after restarting aStaxEventItemWriter. I planned to merge it in 6.1.0 and 6.0.x.