Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 339925

Summary: Binder is not removing null attributes
Product: z_Archived Reporter: Blaise Doughan <blaise.doughan>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: kat, matt.macivor
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Sample code to demonstrate issue.
none
propsed fix and tests none

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