spring-projects / spring-projects/spring-batch

Jackson2ExecutionContextStringSerializer ignores QName prefix

Open Beginner friendly
#4,697 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: bug
Dominant language
Java
Stars
3k
Forks
2.5k
Avg merge
6d 53m
Merged PRs (30d)
3

Description

Bug description
See https://github.com/FasterXML/jackson-databind/issues/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:

https://github.com/spring-projects/spring-batch/blob/fc1f3fcfc791196273b1249157c4e860b1df9025/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java#L796-L799

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Jackson2ExecutionContextStringSerializer and run the QName round-trip reproduction from the issue. Trace how QName values are serialized and deserialized, then add or update a regression test so the namespace URI, local part, and prefix are all preserved; done means the shown prefix assertion passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.