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

Bug 321235

Summary: @XmlRootElement & @XmlAnyElement - Wrong capitilization on element names
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    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
MOXy - Test Cases
none
MOXy - Fix none

Description Blaise Doughan CLA 2010-07-29 10:44:24 EDT
The following code produces:

<zoo><Dog/><Cat/></zoo>

but should produce:

<zoo><dog/><cat/></zoo>


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
class Zoo {

    @XmlElementWrapper
    @XmlAnyElement(lax = true)
    private List<Animal> animals;

    public static void main(String[] args) throws Exception {
        Zoo zoo = new Zoo();
        zoo.animals = new ArrayList<Animal>();
        zoo.animals.add(new Dog());
        zoo.animals.add(new Cat());

        JAXBContext jc = JAXBContext.newInstance(Zoo.class, Dog.class,
                Cat.class);
        System.out.println(jc);
        Marshaller marshaller = jc.createMarshaller();

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        marshaller.marshal(zoo, os);

        System.out.println(os.toString());

        Unmarshaller unmarshaller = jc.createUnmarshaller();
        Zoo unmarshalledZoo = (Zoo) unmarshaller
                .unmarshal(new ByteArrayInputStream(os.toByteArray()));

        if (unmarshalledZoo.animals == null) {
            System.out.println("animals was null");
        } else if (unmarshalledZoo.animals.size() == 2) {
            System.out.println("it worked");
        } else {
            System.out.println("failed!");
        }
    }

    public interface Animal {
    }

    @XmlRootElement
    public static class Dog implements Animal {
    }

    @XmlRootElement
    public static class Cat implements Animal {
    }
}
Comment 1 Blaise Doughan CLA 2010-11-02 13:11:12 EDT
Created attachment 182221 [details]
MOXy - Test Cases
Comment 2 Blaise Doughan CLA 2010-11-02 14:02:21 EDT
Created attachment 182224 [details]
MOXy - Fix

After some investigation this problem only appears to occur on inner classes.  We derive the class name by taking everything after the last '.'.  When we called getQualifiedName on the class inner class names were being returned with a '$' in the class name.  This has been resolved by using getRawName instead.
Comment 3 Blaise Doughan CLA 2010-11-03 10:20:05 EDT
Fix checked into trunk at rev:  8462

Code reviewed by Matt MacIvor
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:19:18 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink