Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 321235 - @XmlRootElement & @XmlAnyElement - Wrong capitilization on element names
Summary: @XmlRootElement & @XmlAnyElement - Wrong capitilization on element names
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: 2010-07-29 10:44 EDT by Blaise Doughan CLA
Modified: 2022-06-09 10:19 EDT (History)
0 users

See Also:


Attachments
MOXy - Test Cases (3.45 KB, patch)
2010-11-02 13:11 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy - Fix (1.41 KB, patch)
2010-11-02 14:02 EDT, Blaise Doughan 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 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