You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Kiril Gavrailov <kg...@gmail.com> on 2013/08/14 14:35:56 UTC

Inheritance of resources and entities

Hi,
My colleagues and I are making a REST service that should provide CRUD
among couple of different jpa entities.

In order not to repeat code for every new entity we have the following
setup:
1. There is and AbstractCrudResource with crud methods annotated @POST,
@GET, @PUT and @DELETE respectively
2. The abstract crud resource class is typed class.
3. All methods accept as arguments the type pointed into the typed class.
4. Every new resource extends the abstract class and adds the @Path
annotation and also passes the type of the entity it is responsible for.
5. Also we have a custom json provider using the gson library

For the JPA we have:
1. Abstract base JPA entity
2. Every new entity extends the abstract one.


The issue: when I make a post request to a particular resource in the
custom gson json provider in the "readFrom" method the clazz and the type
variables I get
are the type of the abstract JPA entity instead of the type which is passed
in the particular rest resource. Example:
Let's say I have
public class SomeResource extends AbstractCrudResource<SomeEntity>{...}
public class SomeEntity extends BaseEntity {...}
what happens is that in the Gson json provider the type that comes is
BaseEntity, but not SomeEntity.

Looking at the CXF code I noticed that in the JAXRSUtils.processParameters
method there's some code which most probably returns the parent class
instead of the child.

Can you give me some advice? How can I get some context about what is
called in the custom json provider in order to get to the child entity?
My backup option is to override all the crud methods in every child class
and call the super methods, but I really don't want to do that.

Regards,
Kiril

Re: Inheritance of resources and entities

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

I'm hoping I've fixed it as part of
https://issues.apache.org/jira/browse/CXF-5204

Please try the snapshots a bit later on
Thanks, Sergey
On 14/08/13 15:42, Sergey Beryozkin wrote:
> Hi
>
> I'm fixing this particular issue right now, you probably have
>
> AbstractCrudResource<T extends BaseEntity>.
>
> Robert T. has reported the same issue few days ago.
> I'll update this thread once I'm done with my tests
>
> Thanks, Sergey
>
>
>
> On 14/08/13 15:35, Kiril Gavrailov wrote:
>> Hi,
>> My colleagues and I are making a REST service that should provide CRUD
>> among couple of different jpa entities.
>>
>> In order not to repeat code for every new entity we have the following
>> setup:
>> 1. There is and AbstractCrudResource with crud methods annotated @POST,
>> @GET, @PUT and @DELETE respectively
>> 2. The abstract crud resource class is typed class.
>> 3. All methods accept as arguments the type pointed into the typed class.
>> 4. Every new resource extends the abstract class and adds the @Path
>> annotation and also passes the type of the entity it is responsible for.
>> 5. Also we have a custom json provider using the gson library
>>
>> For the JPA we have:
>> 1. Abstract base JPA entity
>> 2. Every new entity extends the abstract one.
>>
>>
>> The issue: when I make a post request to a particular resource in the
>> custom gson json provider in the "readFrom" method the clazz and the type
>> variables I get
>> are the type of the abstract JPA entity instead of the type which is
>> passed
>> in the particular rest resource. Example:
>> Let's say I have
>> public class SomeResource extends AbstractCrudResource<SomeEntity>{...}
>> public class SomeEntity extends BaseEntity {...}
>> what happens is that in the Gson json provider the type that comes is
>> BaseEntity, but not SomeEntity.
>>
>> Looking at the CXF code I noticed that in the
>> JAXRSUtils.processParameters
>> method there's some code which most probably returns the parent class
>> instead of the child.
>>
>> Can you give me some advice? How can I get some context about what is
>> called in the custom json provider in order to get to the child entity?
>> My backup option is to override all the crud methods in every child class
>> and call the super methods, but I really don't want to do that.
>>
>> Regards,
>> Kiril
>>
>



Re: Inheritance of resources and entities

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

I'm fixing this particular issue right now, you probably have

AbstractCrudResource<T extends BaseEntity>.

Robert T. has reported the same issue few days ago.
I'll update this thread once I'm done with my tests

Thanks, Sergey



On 14/08/13 15:35, Kiril Gavrailov wrote:
> Hi,
> My colleagues and I are making a REST service that should provide CRUD
> among couple of different jpa entities.
>
> In order not to repeat code for every new entity we have the following
> setup:
> 1. There is and AbstractCrudResource with crud methods annotated @POST,
> @GET, @PUT and @DELETE respectively
> 2. The abstract crud resource class is typed class.
> 3. All methods accept as arguments the type pointed into the typed class.
> 4. Every new resource extends the abstract class and adds the @Path
> annotation and also passes the type of the entity it is responsible for.
> 5. Also we have a custom json provider using the gson library
>
> For the JPA we have:
> 1. Abstract base JPA entity
> 2. Every new entity extends the abstract one.
>
>
> The issue: when I make a post request to a particular resource in the
> custom gson json provider in the "readFrom" method the clazz and the type
> variables I get
> are the type of the abstract JPA entity instead of the type which is passed
> in the particular rest resource. Example:
> Let's say I have
> public class SomeResource extends AbstractCrudResource<SomeEntity>{...}
> public class SomeEntity extends BaseEntity {...}
> what happens is that in the Gson json provider the type that comes is
> BaseEntity, but not SomeEntity.
>
> Looking at the CXF code I noticed that in the JAXRSUtils.processParameters
> method there's some code which most probably returns the parent class
> instead of the child.
>
> Can you give me some advice? How can I get some context about what is
> called in the custom json provider in order to get to the child entity?
> My backup option is to override all the crud methods in every child class
> and call the super methods, but I really don't want to do that.
>
> Regards,
> Kiril
>