Skip to content

Add setter for "standalone" attribute in StaxEventItemWriter #758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Nov 6, 2019 · 6 comments
Closed

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 6, 2019

Mahmoud Ben Hassine opened BATCH-2856 and commented

As of v4.2.0, the only way to add the standalone attribute in the XML declaration of the output file of StaxEventItemWriter is to extend the writer and override startDocument (as stated in its javadoc). Here is an example:

@Bean
public StaxEventItemWriter<Person> itemWriter() {
    StaxEventItemWriter<Person> itemWriter = new StaxEventItemWriter<Person>() {
        @Override
        protected void startDocument(XMLEventWriter writer) throws XMLStreamException {
            writer.add(createXmlEventFactory().createStartDocument(DEFAULT_ENCODING, DEFAULT_XML_VERSION, true));
            writer.add(xmlEventFactory.createStartElement(getRootTagNamespacePrefix(), getRootTagNamespace(), getRootTagName()));
        }
    };
    // TODO set other properties on the writer
    return itemWriter;
}

The StaxEventItemWriter provides setters for the version and encoding attributes, but not for the standalone attribute. I believe it can also provide a setter for standalone as this will make it easier to customize the XML declaration rather than having to extend the writer and override startDocument (which is error prone BTW if we forget to add the root element as shown in the example above).

NB: The example shown above works with Java 9+, see https://bugs.openjdk.java.net/browse/JDK-8139584


Affects: 4.2.0

Reference URL: https://stackoverflow.com/questions/58714744/staxeventitemwriter-xml-header

@spring-projects-issues spring-projects-issues added type: feature has: backports Legacy label from JIRA. Superseded by "for: backport-to-x.x.x" in: infrastructure labels Dec 16, 2019
@spring-projects-issues spring-projects-issues added this to the 4.3.0 milestone Dec 16, 2019
@mminella mminella self-assigned this Mar 4, 2020
@parikshitdutta
Copy link
Contributor

Hi @mminella, just wanted to check with you, if you are active on this one, or I can give it a try.

Thank you.

@mminella
Copy link
Member

Hi @parikshitdutta I assigned this to you as your requested. Let me know if you don't have time to work on it.

@parikshitdutta
Copy link
Contributor

Thanks @mminella, I will take care of it.

@parikshitdutta
Copy link
Contributor

Hi @mminella,
To complete this task, it seems, we need to upgrade stax2-api from 4.2 to 4.2.1, in our case woodstox-core from 6.2.0 to 6.2.1

Reason:
stax2-api-4.2 ignores standalone attribute completely, check here:
https://github.com/FasterXML/stax2-api/blob/1bcbcf1e81a9820adfe45acbee94ae65187c72f7/src/main/java/org/codehaus/stax2/ri/Stax2EventWriterImpl.java#L84-L89

whereas, stax2-api-4.2.1 seems to fix this part, check here:
https://github.com/FasterXML/stax2-api/blob/8f10bb50124cb70048a3ec8dd2dca4421a04733c/src/main/java/org/codehaus/stax2/ri/Stax2EventWriterImpl.java#L84-L91

Thank you.

@parikshitdutta
Copy link
Contributor

parikshitdutta commented Aug 20, 2020

Hi @mminella,
Based on my observation mentioned here: #758 (comment) and only patch level upgrade required for woodstox-core, I thought it would be okay for me to update the build script.

Please have a look at PR #3764, I will look forward to your feedback.

Thank you.

@fmbenhassine fmbenhassine removed the has: backports Legacy label from JIRA. Superseded by "for: backport-to-x.x.x" label Aug 21, 2020
@fmbenhassine
Copy link
Contributor

Resolved with #3764 .

@fmbenhassine fmbenhassine changed the title Add setter for "standalone" attribute in StaxEventItemWriter [BATCH-2856] Add setter for "standalone" attribute in StaxEventItemWriter Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants