Note that there are some explanatory texts on larger screens.

plurals
  1. POJersey REST/ JAXB error , mapping an Interface
    text
    copied!<p>I have to use an interface in my REST web service. Here is the Interface Specs.java :</p> <pre><code>@XmlJavaTypeAdapter(MyAdapter.class) public interface Specs { public BaseProperties getBaseProps(); public void setBaseProps(BaseProperties baseProps); } </code></pre> <p>MyAdapter.java :</p> <pre><code>public class MyAdapter extends XmlAdapter&lt;Object,Object&gt; { public Object unmarshal(Object v) { return v; } public Object marshal(Object v) { return v; } } </code></pre> <p>RegSpecs.java</p> <pre><code>@XmlType public class RegSpecs implements Specs{ private BaseProperties baseProps; public BaseProperties getBaseProps() { return baseProps; } public void setBaseProps(BaseProperties baseProps) { this.baseProps = baseProps; } } </code></pre> <p>MapSpecs.java</p> <pre><code>@XmlType public class MagSpecs implements Specs { private BaseProperties baseProps; private Features features; public BaseProperties getBaseProps() { return baseProps; } public void setBaseProps(BaseProperties baseProps) { this.baseProps = baseProps; } public Features getFeatures() { return features; } public void setFeatures(Features features) { this.features = features; } } </code></pre> <p>Accessing this service throws the following error :</p> <blockquote> <p>javax.xml.bind.MarshalException - with linked exception: [javax.xml.bind.JAXBException: class entities.MagSpecs nor any of its super class is known to this context.]</p> </blockquote> <p>How to modify my context ? I am using JAXB bundled with Jersey 1.5</p> <p>Thanks !</p> <p>EDIT : In an attempt to update my context, I added this code to my client (resource) class :</p> <pre><code>public class BookService implements ContextResolver&lt;JAXBContext&gt; { private JAXBContext jaxbContext; public BookService() { try { // Bootstrap your JAXBContext will all necessary classes jaxbContext = JAXBContext.newInstance(Specs.class,MagSpecs.class, RegSpecs.class); } catch(Exception e) { throw new RuntimeException(e); } } public JAXBContext getContext(Class&lt;?&gt; clazz) { if(BookService.class == clazz) { return jaxbContext; } return null; } </code></pre> <p>In this case I get error :</p> <blockquote> <p>entities.Specs is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at entities.Specs entities.Specs does not have a no-arg default constructor. this problem is related to the following location: at entities.Specs</p> </blockquote>
 

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