After changing javax.xml.bind to jakarta.xml.bind getting missing an @XmlRootElement annotation issue. Annotation @XmlRootElement is already present in the Car class. can you please help me on this.
jakarta.xml.bind.MarshalException with linked exception: [com.sun.istack.SAXException2: unable to marshal type "com.test.v2.Car" as an element because it is missing an @XmlRootElement annotation]
Using code for Marshalling:
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
JAXBContext jaxbContext = JAXBContext.newInstance(Car.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(car, byteArrayOutputStream);
byteArrayOutputStream.close();
String payloadString = String.valueOf(byteArrayOutputStream);
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
name = "",
propOrder = {
"a",
"b",
"c"
}
)
@XmlRootElement(
name = "Car"
)
public class Car {
String a;
String b;
String c;
public String getA() {
return this.A;
}
public String getB() {
return this.B;
}
public String getC() {
return this.C;
}
}