Which annotation is used in JAXB to map a Java class to an XML element?

Which annotation is used in JAXB to map a Java class to an XML element?

A) @XmlElement
B) @XmlType
C) @XmlRootElement
D) @XmlAccessorType

Answer:

C) @XmlRootElement

Explanation:

The @XmlRootElement annotation in JAXB is used to map a Java class to an XML element. This annotation indicates that the class represents the root element of the XML document.

For example:


@XmlRootElement
public class User {
    private String name;
    private int age;

    // Getters and setters
}

In this example, the User class is mapped to the root element of the XML document.

Reference links:

https://www.javaguides.net/p/java-xml-tutorial.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top