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 3878508
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:37:15+00:00 2026-05-19T22:37:15+00:00

I have to use an interface in my REST web service. Here is the

  • 0

I have to use an interface in my REST web service. Here is the Interface Specs.java :

@XmlJavaTypeAdapter(MyAdapter.class)
public interface Specs {

    public BaseProperties getBaseProps();
    public void setBaseProps(BaseProperties baseProps);

}

MyAdapter.java :

public class MyAdapter extends XmlAdapter<Object,Object> 
{  
    public Object unmarshal(Object v) 
    { 
        return v; 
    }  
    public Object marshal(Object v) 
    { 
        return v; 
    }
}

RegSpecs.java

@XmlType
public class RegSpecs implements Specs{
private BaseProperties baseProps;

    public BaseProperties getBaseProps()
    {
        return baseProps;
    }
    public void setBaseProps(BaseProperties baseProps)
    {
        this.baseProps = baseProps;
    }

}

MapSpecs.java

@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;
    }

}

Accessing this service throws the following error :

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.]

How to modify my context ? I am using JAXB bundled with Jersey 1.5

Thanks !

EDIT : In an attempt to update my context, I added this code to my client (resource) class :

public class BookService  implements ContextResolver<JAXBContext> 
{

        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<?> clazz) {
            if(BookService.class == clazz) {
                return jaxbContext;
            }
            return null;
        }

In this case I get error :

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

  • 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-05-19T22:37:15+00:00Added an answer on May 19, 2026 at 10:37 pm

    The client of the Specs interface needs to know that MagSpecs 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 @XmlSeeAlso annotation on the Specs interface:

    @XmlSeeAlso({ MagSpecs.class, RegSpecs.class })
    @XmlJavaTypeAdapter(MyAdapter.class) // Never needed this annotation myself...
    public interface Specs {
        public BaseProperties getBaseProps();
        public void setBaseProps(BaseProperties baseProps);
    }
    

    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):

    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<?>... classes) throws Exception {
        JAXBContext.newInstance(classes).generateSchema(sink);
        Assert.assertTrue(schema.toString().length() > 0);
    }
    
    @Test
    public void testJAXBForSpecs() throws Exception {
        testJAXB(Specs.class);
    }
    

    [EDIT]: You also need to change the Specs 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a web application providing a service using a simple REST interface (GET/POST
I have a REST web-service interface that calls-down to a service layer which orchestrates
If use MongoRepository, You can have following code: @Repository public interface UserRepo extends MongoRepository<User,
I have a WCF-REST service with one method which returns a string: [ServiceContract] public
Okay so, I have to use an interface in a code I'm making involving
(By the way, I don't use Interface Builder) I have a little project consisting
I have to interface with a slightly archaic system that doesn't use webservices. In
I use Qt designer to make an interface and I have an QWebView in
Does C++ have a proper implementation of interface that does not use vtable? for
I have added a JavaScript Interface to WebView. I am able to use all

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.