Skip to content

Jackson2ExecutionContextStringSerializer ignores QName prefix #4697

Open
@jpraet

Description

@jpraet

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:

if (!unclosedHeaderCallbackElements.isEmpty()) {
executionContext.put(getExecutionContextKey(UNCLOSED_HEADER_CALLBACK_ELEMENTS_NAME),
unclosedHeaderCallbackElements);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions