You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
If a class, which should be serialized, extends another class with no zero argument constructor, an error occurs. To Reproduce
The description of the bug is based on the example specified here: https://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted/TheBasics
Suppose we have a class Customer which should be serialized to XML:
package example.gettingstarted;
public class Customer extends Supercustomer {
private String name;
public Customer() {
super("Super");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
The class Supercustomer is given below, note that it does not have a zero argument constructor:
package example.gettingstarted;
public class Supercustomer {
String name;
public Supercustomer(String name){
this.name = name;
}
}
The class Demo.java is used to serialize an object of Customer to XML:
package example.gettingstarted;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;
import javax.xml.namespace.QName;
public class Demo {
public static void main(String[] args) throws JAXBException {
// Step 1 - Create the Domain Model
Customer customer = new Customer();
customer.setName("Jane Doe");
// Step 2 - Convert the Domain Model to XML
JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
JAXBElement<Customer> jaxbElement = new JAXBElement<Customer>(new QName(null, "customer"), Customer.class, customer);
marshaller.marshal(jaxbElement, System.out);
}
}
On execution, the following error occurs:
[Exception [EclipseLink-50001] (Eclipse Persistence Services - 4.0.2.v202306161219): org.eclipse.persistence.exceptions.JAXBException
Exception Description: The class example.gettingstarted.Supercustomer requires a zero argument constructor or a specified factory method. Note that non-static inner classes do not have zero argument constructors and are not supported.]
at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:1173)
at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:208)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:167)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:154)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:114)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:104)
at org.eclipse.persistence.jaxb.XMLBindingContextFactory.createContext(XMLBindingContextFactory.java:43)
at jakarta.xml.bind.ContextFinder.find(ContextFinder.java:368)
at jakarta.xml.bind.JAXBContext.newInstance(JAXBContext.java:605)
at jakarta.xml.bind.JAXBContext.newInstance(JAXBContext.java:546)
at example.gettingstarted.Demo.main(Demo.java:20)
Caused by: Exception [EclipseLink-50001] (Eclipse Persistence Services - 4.0.2.v202306161219): org.eclipse.persistence.exceptions.JAXBException
Exception Description: The class example.gettingstarted.Supercustomer requires a zero argument constructor or a specified factory method. Note that non-static inner classes do not have zero argument constructors and are not supported.
at org.eclipse.persistence.exceptions.JAXBException.factoryMethodOrConstructorRequired(JAXBException.java:150)
at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.finalizeProperties(AnnotationsProcessor.java:961)
at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processClassesAndProperties(AnnotationsProcessor.java:309)
at org.eclipse.persistence.jaxb.compiler.Generator.<init>(Generator.java:154)
at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:1169)
... 10 more
EclipseLink version: 4.0.2
Java/JDK version: 17
Expected behavior
The class, which extends another class, can be serialized, even if the superclass does not have a zero argument constructor.
The text was updated successfully, but these errors were encountered:
Describe the bug
If a class, which should be serialized, extends another class with no zero argument constructor, an error occurs.
To Reproduce
The description of the bug is based on the example specified here:
https://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted/TheBasics
Suppose we have a class Customer which should be serialized to XML:
The class Supercustomer is given below, note that it does not have a zero argument constructor:
The class
Demo.java
is used to serialize an object ofCustomer
to XML:On execution, the following error occurs:
Expected behavior
The class, which extends another class, can be serialized, even if the superclass does not have a zero argument constructor.
The text was updated successfully, but these errors were encountered: