You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Marc Schipperheyn <ma...@orangebits.nl> on 2010/12/20 10:15:07 UTC

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
publicclassParentVO{
String label;
}
publicclassChildVOextendsParentVO{
String label;
int count;
}

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

ResponseObject response=importProxy.importContent(request);
||
PHP Code:
||publicclassRequestObject{
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= newChildVO();
vo.setLabel("Hello");
vo.setCount(1);

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

ResponseObject response=importProxy.importContent(request);
ResponseObject response=importProxy.importChild(request);
||
PHP Code:
||publicclassRequestObject<TextendsParentVO>{
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<ChildVO>bean){
}
||
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.
I'm using Spring 3.0.5 and CXF 2.3.0

Kind regards,

Marc




	


Re: JAX-RS: inheritance in server method

Posted by Marc Schipperheyn <ma...@orangebits.nl>.
Thanks! The XmlSeeAlso worked like a charm!
You saved me a lot of time!

On 20-12-2010 11:44, Sergey Beryozkin wrote:
> Hi
>
> I think it is a JAXB level issue. You may want to try add explicit
> @XmlSeeAlso annotations - just to verify it can help.
> Adding a jaxb.index (I've never used them myself though) or ObjectFactory
> may also help. You may also want to try extend JAXBElementProvider and
> override its createJAXBContext method.
> Another option is to wrap CXF JAXB DataBinding inside a DataBindingProvider,
> see [1] for an example and then configure this data binding to take extra
> classes into consideration,
>
> <jaxrs:dataBinding>
>        <bean class="org.apache.*cxf*.*jaxb*.*JAXBDataBinding*">
>          <property name="*extraClass*">
>            <list>
>              <value>my.service.*ExtraClass1*</value>
>              <value>my.service.*ExtraClass2*</value>
>            </list>
>          </property>
>        </bean>
>   </jaxrs:dataBinding>
>
> something that JAXBElementProvider will also support.
>
> Hope it helps, Sergey
>
> [1]
> http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml
>
>
> On Mon, Dec 20, 2010 at 10:32 AM, Marc Schipperheyn<ma...@orangebits.nl>wrote:
>
>> Tried removing the XmlRootElement tag from ParentVO: same result
>> Tried removing the XmlRootElement tag from ParentVO and making it abstract
>> which results in an unspecified 500 error, which is not logged on the
>> server.
>>
>> There seems to be an irresistible desire to cast down to the base class.
>> :-) Very confusing.
>>
>> BTW I see that the mailing list removed destroyed some code here:
>> public classChildVO extends ParentVO{
>> String label;
>> int count;
>> }
>>
>> public class RequestObject<T extends ParentVO>{
>> T vo;
>> }
>>
>> I assume that the T extends ParentVO is the culprit here. Because,
>> regardless of what I do, Everything leaves as a ChildVO but arrives as a
>> ParentVO.
>> It would also explain why making ParentVO abstract doesn't work.
>> Apparently, it tries to instantiate ParentVO.
>>
>> So, is this some kind of bug or am I doing some wrong? Do I need to
>> implement some custom processing? It all seems illogical to me.
>>
>>
>> On 20-12-2010 10:44, Marc Schipperheyn wrote:
>>
>>> I have both ParentVO and ChildVO tagged as XmlRootElement
>>> @XmlRootElement(name = "parent")
>>> public class ParentVO
>>>
>>> @XmlRootElement(name = "child")
>>> public class ChildVO
>>>
>>>
>>> On 20-12-2010 10:15, Marc Schipperheyn wrote:
>>>
>>>> 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
>>>> publicclassParentVO{
>>>> String label;
>>>> }
>>>> publicclassChildVOextendsParentVO{
>>>> String label;
>>>> int count;
>>>> }
>>>>
>>>> client
>>>> ChildVO vo= newChildVO();
>>>> vo.setLabel("Hello");
>>>> vo.setCount(1);
>>>> RequestObject request= newRequestObject();
>>>> request.setVO(vo);
>>>>
>>>> ResponseObject response=importProxy.importContent(request);
>>>> ||
>>>> PHP Code:
>>>> ||publicclassRequestObject{
>>>> 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= newChildVO();
>>>> vo.setLabel("Hello");
>>>> vo.setCount(1);
>>>>
>>>> RequestObject<ChildVO>request= newRequestObject<ChildVO>();
>>>> request.setVO(vo);
>>>>
>>>> ResponseObject response=importProxy.importContent(request);
>>>> ResponseObject response=importProxy.importChild(request);
>>>> ||
>>>> PHP Code:
>>>> ||publicclassRequestObject<TextendsParentVO>{
>>>> 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<ChildVO>bean){
>>>> }
>>>> ||
>>>> 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.
>>>> I'm using Spring 3.0.5 and CXF 2.3.0
>>>>
>>>> Kind regards,
>>>>
>>>> Marc
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>> --
>>
>> M.Schipperheyn
>> /Principal Consultant/
>>
>> Orange bits
>>
>> www.orangebits.nl<http://www.orangebits.nl>     t: +31 6 218 03 003
>> marc@orangebits.nl<ma...@orangebits.nl>   skype: orangebits
>>
>>

-- 

M.Schipperheyn
/Principal Consultant/

Orange bits

www.orangebits.nl <http://www.orangebits.nl> 	t: +31 6 218 03 003
marc@orangebits.nl <ma...@orangebits.nl> 	skype: orangebits


Re: JAX-RS: inheritance in server method

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

I think it is a JAXB level issue. You may want to try add explicit
@XmlSeeAlso annotations - just to verify it can help.
Adding a jaxb.index (I've never used them myself though) or ObjectFactory
may also help. You may also want to try extend JAXBElementProvider and
override its createJAXBContext method.
Another option is to wrap CXF JAXB DataBinding inside a DataBindingProvider,
see [1] for an example and then configure this data binding to take extra
classes into consideration,

<jaxrs:dataBinding>
      <bean class="org.apache.*cxf*.*jaxb*.*JAXBDataBinding*">
        <property name="*extraClass*">
          <list>
            <value>my.service.*ExtraClass1*</value>
            <value>my.service.*ExtraClass2*</value>
          </list>
        </property>
      </bean>
 </jaxrs:dataBinding>

something that JAXBElementProvider will also support.

Hope it helps, Sergey

[1]
http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml


On Mon, Dec 20, 2010 at 10:32 AM, Marc Schipperheyn <ma...@orangebits.nl>wrote:

> Tried removing the XmlRootElement tag from ParentVO: same result
> Tried removing the XmlRootElement tag from ParentVO and making it abstract
> which results in an unspecified 500 error, which is not logged on the
> server.
>
> There seems to be an irresistible desire to cast down to the base class.
> :-) Very confusing.
>
> BTW I see that the mailing list removed destroyed some code here:
> public classChildVO extends ParentVO{
> String label;
> int count;
> }
>
> public class RequestObject<T extends ParentVO>{
> T vo;
> }
>
> I assume that the T extends ParentVO is the culprit here. Because,
> regardless of what I do, Everything leaves as a ChildVO but arrives as a
> ParentVO.
> It would also explain why making ParentVO abstract doesn't work.
> Apparently, it tries to instantiate ParentVO.
>
> So, is this some kind of bug or am I doing some wrong? Do I need to
> implement some custom processing? It all seems illogical to me.
>
>
> On 20-12-2010 10:44, Marc Schipperheyn wrote:
>
>> I have both ParentVO and ChildVO tagged as XmlRootElement
>> @XmlRootElement(name = "parent")
>> public class ParentVO
>>
>> @XmlRootElement(name = "child")
>> public class ChildVO
>>
>>
>> On 20-12-2010 10:15, Marc Schipperheyn wrote:
>>
>>> 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
>>> publicclassParentVO{
>>> String label;
>>> }
>>> publicclassChildVOextendsParentVO{
>>> String label;
>>> int count;
>>> }
>>>
>>> client
>>> ChildVO vo= newChildVO();
>>> vo.setLabel("Hello");
>>> vo.setCount(1);
>>> RequestObject request= newRequestObject();
>>> request.setVO(vo);
>>>
>>> ResponseObject response=importProxy.importContent(request);
>>> ||
>>> PHP Code:
>>> ||publicclassRequestObject{
>>> 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= newChildVO();
>>> vo.setLabel("Hello");
>>> vo.setCount(1);
>>>
>>> RequestObject<ChildVO>request= newRequestObject<ChildVO>();
>>> request.setVO(vo);
>>>
>>> ResponseObject response=importProxy.importContent(request);
>>> ResponseObject response=importProxy.importChild(request);
>>> ||
>>> PHP Code:
>>> ||publicclassRequestObject<TextendsParentVO>{
>>> 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<ChildVO>bean){
>>> }
>>> ||
>>> 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.
>>> I'm using Spring 3.0.5 and CXF 2.3.0
>>>
>>> Kind regards,
>>>
>>> Marc
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
> --
>
> M.Schipperheyn
> /Principal Consultant/
>
> Orange bits
>
> www.orangebits.nl <http://www.orangebits.nl>    t: +31 6 218 03 003
> marc@orangebits.nl <ma...@orangebits.nl>  skype: orangebits
>
>

Re: JAX-RS: inheritance in server method

Posted by Marc Schipperheyn <ma...@orangebits.nl>.
Tried removing the XmlRootElement tag from ParentVO: same result
Tried removing the XmlRootElement tag from ParentVO and making it 
abstract which results in an unspecified 500 error, which is not logged 
on the server.

There seems to be an irresistible desire to cast down to the base class. 
:-) Very confusing.

BTW I see that the mailing list removed destroyed some code here:
public classChildVO extends ParentVO{
String label;
int count;
}

public class RequestObject<T extends ParentVO>{
T vo;
}

I assume that the T extends ParentVO is the culprit here. Because, 
regardless of what I do, Everything leaves as a ChildVO but arrives as a 
ParentVO.
It would also explain why making ParentVO abstract doesn't work. 
Apparently, it tries to instantiate ParentVO.

So, is this some kind of bug or am I doing some wrong? Do I need to 
implement some custom processing? It all seems illogical to me.

On 20-12-2010 10:44, Marc Schipperheyn wrote:
> I have both ParentVO and ChildVO tagged as XmlRootElement
> @XmlRootElement(name = "parent")
> public class ParentVO
>
> @XmlRootElement(name = "child")
> public class ChildVO
>
>
> On 20-12-2010 10:15, Marc Schipperheyn wrote:
>> 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
>> publicclassParentVO{
>> String label;
>> }
>> publicclassChildVOextendsParentVO{
>> String label;
>> int count;
>> }
>>
>> client
>> ChildVO vo= newChildVO();
>> vo.setLabel("Hello");
>> vo.setCount(1);
>> RequestObject request= newRequestObject();
>> request.setVO(vo);
>>
>> ResponseObject response=importProxy.importContent(request);
>> ||
>> PHP Code:
>> ||publicclassRequestObject{
>> 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= newChildVO();
>> vo.setLabel("Hello");
>> vo.setCount(1);
>>
>> RequestObject<ChildVO>request= newRequestObject<ChildVO>();
>> request.setVO(vo);
>>
>> ResponseObject response=importProxy.importContent(request);
>> ResponseObject response=importProxy.importChild(request);
>> ||
>> PHP Code:
>> ||publicclassRequestObject<TextendsParentVO>{
>> 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<ChildVO>bean){
>> }
>> ||
>> 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.
>> I'm using Spring 3.0.5 and CXF 2.3.0
>>
>> Kind regards,
>>
>> Marc
>>
>>
>>
>>
>>
>>
>>
>

-- 

M.Schipperheyn
/Principal Consultant/

Orange bits

www.orangebits.nl <http://www.orangebits.nl> 	t: +31 6 218 03 003
marc@orangebits.nl <ma...@orangebits.nl> 	skype: orangebits


Re: JAX-RS: inheritance in server method

Posted by Marc Schipperheyn <ma...@orangebits.nl>.
I have both ParentVO and ChildVO tagged as XmlRootElement
@XmlRootElement(name = "parent")
public class ParentVO

@XmlRootElement(name = "child")
public class ChildVO


On 20-12-2010 10:15, Marc Schipperheyn wrote:
> 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
> publicclassParentVO{
> String label;
> }
> publicclassChildVOextendsParentVO{
> String label;
> int count;
> }
>
> client
> ChildVO vo= newChildVO();
> vo.setLabel("Hello");
> vo.setCount(1);
> RequestObject request= newRequestObject();
> request.setVO(vo);
>
> ResponseObject response=importProxy.importContent(request);
> ||
> PHP Code:
> ||publicclassRequestObject{
> 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= newChildVO();
> vo.setLabel("Hello");
> vo.setCount(1);
>
> RequestObject<ChildVO>request= newRequestObject<ChildVO>();
> request.setVO(vo);
>
> ResponseObject response=importProxy.importContent(request);
> ResponseObject response=importProxy.importChild(request);
> ||
> PHP Code:
> ||publicclassRequestObject<TextendsParentVO>{
> 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<ChildVO>bean){
> }
> ||
> 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.
> I'm using Spring 3.0.5 and CXF 2.3.0
>
> Kind regards,
>
> Marc
>
>
>
>
>
>
>

-- 

M.Schipperheyn
/Principal Consultant/

Orange bits

www.orangebits.nl <http://www.orangebits.nl> 	t: +31 6 218 03 003
marc@orangebits.nl <ma...@orangebits.nl> 	skype: orangebits