Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8728007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:32:36+00:00 2026-06-13T08:32:36+00:00

When adding JAX-B Java annotations for Java classes – if I have a parent

  • 0

When adding JAX-B Java annotations for Java classes – if I have a parent Class Entry, with two children, Book and JournalArticle,

Would I add these annotations for all three classes:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement

ie:

@XmlSeeAlso({au.com.library.Book.class, au.com.library.JournalArticle.class})
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public abstract class Entry implements Serializable{


private static final long serialVersionUID = -1895155325179947581L;

@XmlElement(name="title")
protected String title;
@XmlElement(name="author")
protected String author;
@XmlElement(name="year")
protected int year;

and

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Book extends Entry {

@XmlElement(name="edition")
private String edition;
@XmlElement(name="publisher")
private String publisher;
@XmlElement(name="placeOfPublication")
private String placeOfPub;

and

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class JournalArticle extends Entry {

@XmlElement(name="journalTitle")
private String journalTitle;
@XmlElement(name="volume")
private String volume;
@XmlElement(name="issue")
private String issue;
@XmlElement(name="pageNumbers")
private String pgNumbers;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:32:37+00:00Added an answer on June 13, 2026 at 8:32 am

    The annotation XmlAccessorType can be inherited so I believe it is not mandatory to declare it again on child classes.

    @Inherited
    @Retention(value=RUNTIME)
    @Target(value={PACKAGE,TYPE})
    public @interface XmlAccessorType
    

    This is not the case for XmlRootElement, so you will have to annotate each base class with it.

    You can find more information on the @Inherited annotation on the javadoc.

    Update for your comment:

    @Retention(value=RUNTIME) means that the class keeps this annotation even at runtime, that is, a program can use the Java reflection API to check if the annotation is present on a class.

    @Target(value={PACKAGE,TYPE}) means that this annotation can be used to annotate classes, interfaces or enums (this is for the value=TYPE), and also at a whole package level (this is for value=PACKAGE). You can see this thread explaining how this can be useful.

    More information on the Javadoc:

    • @Retention
    • RetentionPolicy
    • @Target
    • ElementType
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Adding any noncopyable member to a class would prevent the automatic generation of copy
I've written a JAX-WS webservice in Java by generating a WSDL and classes from
I'm using jax-rs and adding entity for being marshalled in Jetty by JAXRSOutInterceptor, but
Adding Exceptional Handling is a good practise, but I have a doubt, In our
Adding functionality to a class can be done by adding a method or by
Adding member variables to a class certainly boosts the memory footprint of its instances
Adding some gui modifications and I want to have a button which is 10pixels
I am having trouble creating a Web Service in Java that contains two methods
A little up front info: I have a SOAP service (hosted using JAX-WS (Endpoint
Adding two empty arrays: [] + [] results in an empty string. Why?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.