Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The client of the <code>Specs</code> interface needs to know that <code>MagSpecs</code> can be an instance of it so that it knows to look at it for tooling purposes. The easiest way of doing this is to put an <code>@XmlSeeAlso</code> annotation on the <code>Specs</code> interface:</p> <pre><code>@XmlSeeAlso({ MagSpecs.class, RegSpecs.class }) @XmlJavaTypeAdapter(MyAdapter.class) // Never needed this annotation myself... public interface Specs { public BaseProperties getBaseProps(); public void setBaseProps(BaseProperties baseProps); } </code></pre> <p>In general, whenever I'm working with JAXB annotations I make sure I write plenty of tests to check that an XML schema can be generated from the classes in question, checking that from each (sane) entry point into the web of classes and interfaces I can generate a sensible schema without exceptions. For example (and I apologize for this being a bit long):</p> <pre><code>private SchemaOutputResolver sink; StringWriter schema; @Before public void init() { schema = new StringWriter(); sink = new SchemaOutputResolver() { @Override public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException { StreamResult sr = new StreamResult(schema); sr.setSystemId("/dev/null"); return sr; } }; Assert.assertTrue(schema.toString().isEmpty()); } private void testJAXB(Class&lt;?&gt;... classes) throws Exception { JAXBContext.newInstance(classes).generateSchema(sink); Assert.assertTrue(schema.toString().length() &gt; 0); } @Test public void testJAXBForSpecs() throws Exception { testJAXB(Specs.class); } </code></pre> <hr> <p>[EDIT]: You also <em>need</em> to change the <code>Specs</code> interface into a class and have the current implementations inherit from it. It can be a fully abstract class if you want. As long as you're not putting serious functionality in the classes, it should work.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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