| Summary: | Enhancement Request: Should not check that abstract classes have no-arg constructors | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | Blaise Doughan <blaise.doughan> | ||||||
| Component: | Eclipselink | Assignee: | Nobody - feel free to take it <nobody> | ||||||
| Status: | RESOLVED FIXED | QA Contact: | |||||||
| Severity: | enhancement | ||||||||
| Priority: | P3 | CC: | eclipselink.oxm-inbox | ||||||
| Version: | unspecified | ||||||||
| Target Milestone: | --- | ||||||||
| Hardware: | PC | ||||||||
| OS: | Windows XP | ||||||||
| Whiteboard: | |||||||||
| Attachments: |
|
||||||||
Created attachment 185374 [details]
MOXy - Test Cases
Created attachment 185375 [details]
MOXy - Fix
Fix checked into trunk at rev: Code reviewed by: David McCann Fix Description: 8722 Removed check for no-arg constructor or factory method if the class is abstract. The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |
The following example throws an error that ClassA does not have a no-arg constructor. Since ClassA is abstract it doesn't need one. import java.io.File; import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; public class JaxbTest { public static abstract class ClassA { public ClassA(String id) { } } @XmlRootElement @XmlJavaTypeAdapter(MyAdapter.class) // does not have an effect public static class ClassB extends ClassA { public String text; public ClassB() { super(""); } } public static class ValB { public String text; } public static class MyAdapter extends XmlAdapter<ValB, ClassB> { @Override public ClassB unmarshal(ValB v) throws Exception { ClassB b = new ClassB(); b.text = v.text; return b; } @Override public ValB marshal(ClassB v) throws Exception { ValB b = new ValB(); b.text = v.text; return b; } } public static void main(String[] args) { try { JAXBContext context = JAXBContext.newInstance(ClassB.class); Unmarshaller unmarshaller = context.createUnmarshaller(); unmarshaller.setAdapter(new MyAdapter()); // does not have an effect ClassA a = (ClassA) unmarshaller.unmarshal(new File("test.xml")); // do somthing with a } catch (Exception e) { e.printStackTrace(); } } }