Announcement Announcement Module
Collapse
No announcement yet.
JAX-RS: inheritance in server method Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JAX-RS: inheritance in server method

    Hi,

    I'm using JAX-RS and spring 3. I have a problem with inheritance on the receiving end of the service and I'm wondering if there is a way to work around this.
    PHP Code:
    Types of beans sent
    public class ParentVO{
     
    String label;
    }
    public class 
    ChildVO extends ParentVO{
     
    String label;
     
    int count;
    }

    client
    ChildVO vo 
    = new ChildVO();
    vo.setLabel("Hello");
    vo.setCount(1);
    RequestObject request = new RequestObject();
    request.setVO(vo);

    ResponseObject response importProxy.importContent(request); 
    PHP Code:
    public class RequestObject{
     
    ParentVO vo;
    }

    Server JAX-RS client

    @POST
        
    @Path("/import/standard")
        @
    Secured({"ROLE_WS","ROLE_ADMIN"})
        @
    Produces("text/xml")
        public 
    ResponseObject importContent(RequestObject bean){

    I'm trying to work with a single importContent method in stead of creating one specific to eaach type of bean.

    But "vo" is always of type ParentVO including when a ChildVO is sent.

    Is there a way to do this with JAX-RS?

    I've also tried the following with the same result.
    PHP Code:
    client
    ChildVO vo 
    = new ChildVO();
    vo.setLabel("Hello");
    vo.setCount(1);

    RequestObject<ChildVOrequest = new RequestObject<ChildVO>();
    request.setVO(vo);

    ResponseObject response importProxy.importContent(request);
    ResponseObject response importProxy.importChild(request); 
    PHP Code:
    public class RequestObject<extends ParentVO>{
     
    T vo;
    }

    Server JAX-RS client

    @POST
        
    @Path("/import/standard")
        @
    Secured({"ROLE_WS","ROLE_ADMIN"})
        @
    Produces("text/xml")
        public 
    ResponseObject importContent(RequestObject bean){
    }

    @
    POST
        
    @Path("/import/standard")
        @
    Secured({"ROLE_WS","ROLE_ADMIN"})
        @
    Produces("text/xml")
        public 
    ResponseObject importChild(RequestObject<ChildVObean){

    In the case above both importContent and importChild produced a vo of type ParentVO, which surprised me.

    Any suggestions? Primarily, I would like to avoid unique method signatures for each child.

    Kind regards,

    Marc
Working...
X