Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating abstract generic jaxb class
    primarykey
    data
    text
    <p>I have the following simple jaxB class that takes generic type E</p> <pre><code>@XmlAccessorType(XmlAccessType.FIELD) @XmlTransient @XmlRootElement(name = "searchResponseBase") public abstract class SearchResponseBase&lt;E&gt;{ @XmlElement(type=NameSearchResults.class) protected E searchResults; public E getSearchResults() { return searchResults; } public void setSearchResults(E mSearchResults) { this.searchResults = mSearchResults; } } </code></pre> <p>I need to remove the reference to NameSearchResults <code>@XmlElement(type=NameSearchResults.class)</code> to make the base actually generic, but if I do I get the error.</p> <p><strong>error</strong></p> <pre><code>[com.sun.istack.internal.SAXException2: class au.test.nameSearch.NameSearchResults nor any of its super class is known to this context. javax.xml.bind.JAXBException: class au.test.nameSearch.NameSearchResults nor any of its super class is known to this context.] </code></pre> <p><BR> This is an example of a class that extends it</p> <p><strong>extended class</strong></p> <pre><code>@SuppressWarnings("javadoc") @XmlAccessorType(XmlAccessType.FIELD) @XmlType(propOrder = { "searchRequest", "searchResults" }) @XmlRootElement(name = "searchResponse") public class SearchResponse extends SearchResponseBase&lt;NameSearchResults&gt; { @XmlElement(required = true) protected SearchRequest searchRequest; public SearchRequest getSearchRequest() { return searchRequest; } public void setSearchRequest(SearchRequest value) { this.searchRequest = value; } } </code></pre> <p>How do i make the base class actually generic?</p> <p>preferably i would like my extended class to work in the format <code>SearchResponse&lt;E&gt; extends SearchResponseBase&lt;E&gt;</code> and use it as a generic type too.</p> <p>if i do as paul suggested i can get teh class to:</p> <pre><code>@XmlRootElement(name = "searchResponse") public class SearchResponse&lt;E extends NameSearchResults&gt; extends SearchResponseBase&lt;E&gt; { @XmlElement(required = true) protected SearchRequest searchRequest; protected E searchResults; public SearchRequest getSearchRequest() { return searchRequest; } public void setSearchRequest(SearchRequest value) { this.searchRequest = value; } @Override public E getSearchResults() { return searchResults; } @Override public void setSearchResults(E mSearchResults) { this.searchResults = mSearchResults; } } </code></pre> <p>is there a way i can push the NameSearchResults out of this <code>&lt;E extends NameSearchResults&gt;</code>?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload