Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 339925 - Binder is not removing null attributes
Summary: Binder is not removing null attributes
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-14 13:12 EDT by Blaise Doughan CLA
Modified: 2022-06-09 10:20 EDT (History)
2 users (show)

See Also:


Attachments
Sample code to demonstrate issue. (1.50 KB, application/x-zip-compressed)
2011-03-14 13:15 EDT, Blaise Doughan CLA
no flags Details
propsed fix and tests (6.99 KB, patch)
2011-03-29 14:43 EDT, Matt MacIvor CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Blaise Doughan CLA 2011-03-14 13:12:22 EDT
Given the following XML input:

<?xml version="1.0" encoding="UTF-8"?>
<root parenttool="aValue">
    <!-- COMMENT -->
</root>


If the following code is run:

import java.io.File;
import javax.xml.bind.Binder;
import javax.xml.bind.JAXBContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;

public class Demo {

    public static void main(String[] args) throws Exception {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document document = db.parse(new File("input.xml"));

        JAXBContext jc = JAXBContext.newInstance(Root.class);
        Binder binder = jc.createBinder();

        Root root = (Root) binder.unmarshal(document);
        root.setParentTool(null);
        binder.updateXML(root);

        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer t = tf.newTransformer();
        t.transform(new DOMSource(document), new StreamResult(System.out));
    }
}


The correct output should be:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root>
    <!-- COMMENT -->
</root>


But is currently (the parenttool attribute should have been removed):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root parenttool="">
    <!-- COMMENT -->
</root>
Comment 1 Blaise Doughan CLA 2011-03-14 13:15:47 EDT
Created attachment 191152 [details]
Sample code to demonstrate issue.
Comment 2 Kasper Thuno CLA 2011-03-29 06:20:07 EDT
Any chance that this could be fixed in a nightly build? I'm getting close to a release date in this bug is critical for the usage of the application.
Comment 3 Matt MacIvor CLA 2011-03-29 14:43:23 EDT
Created attachment 192120 [details]
propsed fix and tests
Comment 4 Matt MacIvor CLA 2011-03-29 15:02:23 EDT
Attach patch has been checked in to SVN
Code reviewed by Blaise Doughan

This fix will be available in the next nightly 2.3 build.
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:20:27 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink