You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Simon Chen <si...@gmail.com> on 2011/04/06 23:59:29 UTC

passing objects with reference in jax-rs

Hi all,

I am trying to build a RESTful web service... In short, I am having
trouble posting Java objects with member references from client side
to server side.

I have mostly followed the example under
"apache-cxf-2.3.3/samples/jax_rs/basic". I have two major problems
now...

1) Handle objects with references. For example, a customer may have a
list of orders, and an order may be linked back to a customer. So, how
can I (or indeed what is the best way to) post an "Order" object with
a link to a "Customer" object to "/customerservice/orders"?

2) The example uses annotations like "XmlRootElement" to enable sort
of automated conversioning from java objects to XML/json data. But
this conversion seems to be broken when I add references into a class
definition. For example, when I post an "Order" object to
"/customerservice/orders", the server reports "No message body reader
has been found for request class Order", (even though the customer ref
is set to null).

Thanks.
-Simon

Re: passing objects with reference in jax-rs

Posted by Simon Chen <si...@gmail.com>.
I am a bit confused...

I think there are two ways of converting java objects to XML form. One
way is through the EMF resource thing, which comes directly with the
ecore/genmodel. The other way is to use annotations like
@XmlRootElement, @XmlElementRef.

I thought the serialization of objects in jax-rs depends on the
latter, not the former, right?

Thanks!
-Simon

On Friday, April 8, 2011, Sergey Beryozkin <sb...@gmail.com> wrote:
> Hi
>
> On Fri, Apr 8, 2011 at 5:08 AM, Simon Chen <si...@gmail.com> wrote:
>
> I guest my question should be how I should annotate non-containment
> reference links...
>
> For example, an Order has a "Customer customer" member, when
> converting an Order object to XML, I only want to have a something
> like:
> <order>
>   <name>holiday_purchase</name>
>   <customer>simon</customer>
> </order>
>
> where "simon" is a unique identifier for a Customer object.
>
> How should I annotate "Customer getCustomer()" within the Order class?
>
>
> I'm not sure you can annotate a non-containment link in a way which will affect the serialization of the linked Customer.
>
> What
>  happens if you have Customer itself annotated with a non-containment
> link ? Do you have some EMF reference embedded in this case ? Ideally,
> it would be nice if you could intercept/customize somehow the EMF
> serialization process. You can create a JAX-RS MessageBodyWriter which
> will use EMF to get to objects referenced by non-containment links and
> then serialize them with the help of JAXB or manually. Another option is
>  to try to post-process the EMF output with some transformation, CXF may
>  help there.
>
> Can you post few example, showing the current XML being produced and the one you'd like to be produced ?
>
> Thanks, Sergey
>
>
>
> Thanks.
> -Simon
>
> On Thu, Apr 7, 2011 at 12:36 PM, Sergey Beryozkin <sb...@gmail.com> wrote:
>>
>>
>> On Thu, Apr 7, 2011 at 5:28 PM, Simon Chen <si...@gmail.com> wrote:
>>>
>>> Can you elaborate (or post a link) on this one?
>>>
>>> I am actually modifying the genmodel code (javajetinc files), such
>>> that genmodel would add @XmlRootElement tags automatically. The
>>> downside is that I don't know if I added enough of them, or indeed
>>> where I should add to...
>>>
>> I don't recall the details, may be David B can advise something :-)
>>
>> Cheers, Sergey
>>
>>>
>>> Thanks a lot for your input. I will try them.
>>>
>>> -Simon
>>>
>>> On Thu, Apr 7, 2011 at 12:22 PM, Sergey Beryozkin <sb...@gmail.com>
>>> wrote:
>>> > Actually, another option is to add a custom JAX-RS provider which
>>> > handles
>>> > Order/etc using the EMF itself (which will produce XMI - though it's a
>>> > complex XML indeed)
>>> >
>>> > Sergey
>>> >
>>> > On Thu, Apr 7, 2011 at 5:21 PM, Sergey Beryozkin <sb...@gmail.com>
>>> > wrote:
>>> >>
>>> >> Hi
>>> >>
>>> >> Please see comments inline
>>> >>
>>> >> On Thu, Apr 7, 2011 at 4:55 PM, Simon Chen <si...@gmail.com>
>>> >> wrote:
>>> >>>
>>> >>> I have some new findings...
>>> >>>
>>> >>> My class files are generated by EMF (ecore/genmodel).
>>> >>
>>> >> I guess it can help in time if CXF has an EMF binding or JAX-RS
>>> >> provider
>>> >>
>>> >>>
>>> >>> Thus, I have
>>> >>> both Customer.class and CustomerImpl.class. The code is as simple as:
>>> >>>
>>> >>> @XmlRootElement(name = "Customer")
>>> >>> public class CustomerImpl implements Customer {
>>> >>>        private String name;
>>> >>>        private EList<Order> orders;
>>> >>>        public String getName() {
>>> >>>                return name;
>>> >>>        }
>>> >>>        public void setName(String name) {
>>> >>>                this.name <http://this.name/> = name;
>>> >>>        }
>>> >>>        public Order getOrder(String name) {
>>> >>>                // return the order with the specified name
>>> >>>                return null;
>>> >>>        }
>>> >>>        public void deleteOrder(String name) {
>>> >>>                // remove the order with the specified name
>>> >>>        }
>>> >>> }
>>> >>>
>>> >>> @XmlRootElement(name = "Order")
>>> >>> public class OrderImpl implements Order {
>>> >>>        private String name;
>>> >>>        private Customer customer;
>>> >>>        public String getName() {
>>> >>>                return name;
>>> >>>        }
>>> >>>        public void setName(String name) {
>>> >>>                this.name <http://this.name/> = name;
>>> >>>        }
>>> >>>        public Customer getCustomer() {
>>> >>>                return this.customer;
>>> >>>        }
>>> >>>        public void setCustomer(Customer c) {
>>> >>>                this.customer = c;
>>> >>>        }
>>> >>> }
>>> >>>
>>> >>>
>>> >>> The problem is that under "CustomerService" class, which contains a
>>> >>> list of Customers and Orders, I have:
>>> >>
>
>
>

Re: passing objects with reference in jax-rs

Posted by Sergey Beryozkin <sb...@gmail.com>.
>
> Hi
>
> On Fri, Apr 8, 2011 at 5:08 AM, Simon Chen <si...@gmail.com> wrote:
>
>> I guest my question should be how I should annotate non-containment
>> reference links...
>>
>> For example, an Order has a "Customer customer" member, when
>> converting an Order object to XML, I only want to have a something
>> like:
>> <order>
>>  <name>holiday_purchase</name>
>>  <customer>simon</customer>
>> </order>
>>
>> where "simon" is a unique identifier for a Customer object.
>>
>> How should I annotate "Customer getCustomer()" within the Order class?
>>
>>
> I'm not sure you can annotate a non-containment link in a way which will
> affect the serialization of the linked Customer.
>
> What happens if you have Customer itself annotated with a non-containment
> link ? Do you have some EMF reference embedded in this case ? Ideally, it
> would be nice if you could intercept/customize somehow the EMF serialization
> process. You can create a JAX-RS MessageBodyWriter which will use EMF to get
> to objects referenced by non-containment links and then serialize them with
> the help of JAXB or manually. Another option is to try to post-process the
> EMF output with some transformation, CXF may help there.
>
> Can you post few example, showing the current XML being produced and the
> one you'd like to be produced ?
>
> Thanks, Sergey
>
>
>> Thanks.
>> -Simon
>>
>> On Thu, Apr 7, 2011 at 12:36 PM, Sergey Beryozkin <sb...@gmail.com>
>> wrote:
>> >
>> >
>> > On Thu, Apr 7, 2011 at 5:28 PM, Simon Chen <si...@gmail.com>
>> wrote:
>> >>
>> >> Can you elaborate (or post a link) on this one?
>> >>
>> >> I am actually modifying the genmodel code (javajetinc files), such
>> >> that genmodel would add @XmlRootElement tags automatically. The
>> >> downside is that I don't know if I added enough of them, or indeed
>> >> where I should add to...
>> >>
>> > I don't recall the details, may be David B can advise something :-)
>> >
>> > Cheers, Sergey
>> >
>> >>
>> >> Thanks a lot for your input. I will try them.
>> >>
>> >> -Simon
>> >>
>> >> On Thu, Apr 7, 2011 at 12:22 PM, Sergey Beryozkin <
>> sberyozkin@gmail.com>
>> >> wrote:
>> >> > Actually, another option is to add a custom JAX-RS provider which
>> >> > handles
>> >> > Order/etc using the EMF itself (which will produce XMI - though it's
>> a
>> >> > complex XML indeed)
>> >> >
>> >> > Sergey
>> >> >
>> >> > On Thu, Apr 7, 2011 at 5:21 PM, Sergey Beryozkin <
>> sberyozkin@gmail.com>
>> >> > wrote:
>> >> >>
>> >> >> Hi
>> >> >>
>> >> >> Please see comments inline
>> >> >>
>> >> >> On Thu, Apr 7, 2011 at 4:55 PM, Simon Chen <si...@gmail.com>
>> >> >> wrote:
>> >> >>>
>> >> >>> I have some new findings...
>> >> >>>
>> >> >>> My class files are generated by EMF (ecore/genmodel).
>> >> >>
>> >> >> I guess it can help in time if CXF has an EMF binding or JAX-RS
>> >> >> provider
>> >> >>
>> >> >>>
>> >> >>> Thus, I have
>> >> >>> both Customer.class and CustomerImpl.class. The code is as simple
>> as:
>> >> >>>
>> >> >>> @XmlRootElement(name = "Customer")
>> >> >>> public class CustomerImpl implements Customer {
>> >> >>>        private String name;
>> >> >>>        private EList<Order> orders;
>> >> >>>        public String getName() {
>> >> >>>                return name;
>> >> >>>        }
>> >> >>>        public void setName(String name) {
>> >> >>>                this.name = name;
>> >> >>>        }
>> >> >>>        public Order getOrder(String name) {
>> >> >>>                // return the order with the specified name
>> >> >>>                return null;
>> >> >>>        }
>> >> >>>        public void deleteOrder(String name) {
>> >> >>>                // remove the order with the specified name
>> >> >>>        }
>> >> >>> }
>> >> >>>
>> >> >>> @XmlRootElement(name = "Order")
>> >> >>> public class OrderImpl implements Order {
>> >> >>>        private String name;
>> >> >>>        private Customer customer;
>> >> >>>        public String getName() {
>> >> >>>                return name;
>> >> >>>        }
>> >> >>>        public void setName(String name) {
>> >> >>>                this.name = name;
>> >> >>>        }
>> >> >>>        public Customer getCustomer() {
>> >> >>>                return this.customer;
>> >> >>>        }
>> >> >>>        public void setCustomer(Customer c) {
>> >> >>>                this.customer = c;
>> >> >>>        }
>> >> >>> }
>> >> >>>
>> >> >>>
>> >> >>> The problem is that under "CustomerService" class, which contains a
>> >> >>> list of Customers and Orders, I have:
>> >> >>>
>> >> >>> @Path("/customerservice/')
>> >> >>> public class CustomerService {
>> >> >>>    ...
>> >> >>>    @POST
>> >> >>>    @Path("/customers/")
>> >> >>>    public Response addCustomer(Customer c) {
>> >> >>>        ......
>> >> >>>    }
>> >> >>>    ....
>> >> >>> }
>> >> >>>
>> >> >>> In this case, if I post a CustomerImpl object to
>> >> >>> "/customerservice/customers/", I have the error of "No message body
>> >> >>> reader has been found for request class Customer". If I change the
>> >> >>> function definition to be as follows, it works...
>> >> >>>    @POST
>> >> >>>    @Path("/customers/")
>> >> >>>    public Response addCustomer(CustomerImpl c) {
>> >> >>>        ......
>> >> >>>    }
>> >> >>>
>> >> >>> So, my first question is, is there a more elegant work-around such
>> >> >>> that "addCustomer" function would take "CustomerImpl" objects, even
>> >> >>> when the function parameter says "Customer c"?
>> >> >>>
>> >> >>> My second question is, let's say I want to post an "OrderImpl"
>> object
>> >> >>> to "/customerservice/orders", but the OrderImpl object contains a
>> >> >>> reference to a customer. What is the best way to transfer the
>> >> >>> reference relationship between the client and the server? For some
>> >> >>> reason, the direct XML marshaling would ignore the reference.
>> >> >>>
>> >> >>
>> >> >>
>> >> >> Looks like it does not work because Order and Customer interfaces,
>> >> >> presumably generated by EMF, have no @XmlRootElement annotations
>> >> >> themselves.
>> >> >>
>> >> >> Adding these annotations to concrete implementations is problematic,
>> as
>> >> >> you can add many components in EMF all the time. Some options to
>> >> >> consider:
>> >> >>
>> >> >> - I recall it is possible to add custom metadata to the EMF model.
>> Is
>> >> >> it
>> >> >> possible to have @XmlRootElement added to the generated interfaces ?
>> >> >> - Explicitly configure CXF JAXBElementProvider and set it to use
>> >> >> JAXBElement internally - that should handle types such as Customer
>> and
>> >> >> Order, see
>> >> >>
>> >> >>
>> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-HandlingJAXBbeanswithoutXmlRootElementannotations
>> >> >>
>> >> >> Hope that helps
>> >> >>
>> >> >> Sergey
>> >> >>
>> >> >>>
>> >> >>> Thanks.
>> >> >>> -Simon
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>> On Thu, Apr 7, 2011 at 7:56 AM, Sergey Beryozkin
>> >> >>> <sb...@gmail.com>
>> >> >>> wrote:
>> >> >>> > Hi Simon
>> >> >>> >
>> >> >>> > On Wed, Apr 6, 2011 at 10:59 PM, Simon Chen <
>> simonchennj@gmail.com>
>> >> >>> > wrote:
>> >> >>> >>
>> >> >>> >> Hi all,
>> >> >>> >>
>> >> >>> >> I am trying to build a RESTful web service... In short, I am
>> having
>> >> >>> >> trouble posting Java objects with member references from client
>> >> >>> >> side
>> >> >>> >> to server side.
>> >> >>> >>
>> >> >>> >> I have mostly followed the example under
>> >> >>> >> "apache-cxf-2.3.3/samples/jax_rs/basic". I have two major
>> problems
>> >> >>> >> now...
>> >> >>> >>
>> >> >>> >> 1) Handle objects with references. For example, a customer may
>> have
>> >> >>> >> a
>> >> >>> >> list of orders, and an order may be linked back to a customer.
>> So,
>> >> >>> >> how
>> >> >>> >> can I (or indeed what is the best way to) post an "Order" object
>> >> >>> >> with
>> >> >>> >> a link to a "Customer" object to "/customerservice/orders"?
>> >> >>> >>
>> >> >>> >> 2) The example uses annotations like "XmlRootElement" to enable
>> >> >>> >> sort
>> >> >>> >> of automated conversioning from java objects to XML/json data.
>> But
>> >> >>> >> this conversion seems to be broken when I add references into a
>> >> >>> >> class
>> >> >>> >> definition. For example, when I post an "Order" object to
>> >> >>> >> "/customerservice/orders", the server reports "No message body
>> >> >>> >> reader
>> >> >>> >> has been found for request class Order", (even though the
>> customer
>> >> >>> >> ref
>> >> >>> >> is set to null).
>> >> >>> >>
>> >> >>> >
>> >> >>> > Is that Order class also annotated ? Can you post some sample
>> >> >>> > structures
>> >> >>> > showing what exactly you'd like to do ?
>> >> >>> >
>> >> >>> > Thanks, Sergey
>> >> >>> >
>> >> >>> >>
>> >> >>> >> Thanks.
>> >> >>> >> -Simon
>> >> >>> >
>> >> >>> >
>> >> >>> >
>> >> >>
>> >> >>
>> >> >>
>> >> >> --
>> >> >> Sergey Beryozkin
>> >> >>
>> >> >> Application Integration Division of Talend
>> >> >> http://sberyozkin.blogspot.com
>> >> >
>> >> >
>> >
>> >
>> >
>>
>
>
>

Re: passing objects with reference in jax-rs

Posted by Simon Chen <si...@gmail.com>.
I guest my question should be how I should annotate non-containment
reference links...

For example, an Order has a "Customer customer" member, when
converting an Order object to XML, I only want to have a something
like:
<order>
  <name>holiday_purchase</name>
  <customer>simon</customer>
</order>

where "simon" is a unique identifier for a Customer object.

How should I annotate "Customer getCustomer()" within the Order class?

Thanks.
-Simon

On Thu, Apr 7, 2011 at 12:36 PM, Sergey Beryozkin <sb...@gmail.com> wrote:
>
>
> On Thu, Apr 7, 2011 at 5:28 PM, Simon Chen <si...@gmail.com> wrote:
>>
>> Can you elaborate (or post a link) on this one?
>>
>> I am actually modifying the genmodel code (javajetinc files), such
>> that genmodel would add @XmlRootElement tags automatically. The
>> downside is that I don't know if I added enough of them, or indeed
>> where I should add to...
>>
> I don't recall the details, may be David B can advise something :-)
>
> Cheers, Sergey
>
>>
>> Thanks a lot for your input. I will try them.
>>
>> -Simon
>>
>> On Thu, Apr 7, 2011 at 12:22 PM, Sergey Beryozkin <sb...@gmail.com>
>> wrote:
>> > Actually, another option is to add a custom JAX-RS provider which
>> > handles
>> > Order/etc using the EMF itself (which will produce XMI - though it's a
>> > complex XML indeed)
>> >
>> > Sergey
>> >
>> > On Thu, Apr 7, 2011 at 5:21 PM, Sergey Beryozkin <sb...@gmail.com>
>> > wrote:
>> >>
>> >> Hi
>> >>
>> >> Please see comments inline
>> >>
>> >> On Thu, Apr 7, 2011 at 4:55 PM, Simon Chen <si...@gmail.com>
>> >> wrote:
>> >>>
>> >>> I have some new findings...
>> >>>
>> >>> My class files are generated by EMF (ecore/genmodel).
>> >>
>> >> I guess it can help in time if CXF has an EMF binding or JAX-RS
>> >> provider
>> >>
>> >>>
>> >>> Thus, I have
>> >>> both Customer.class and CustomerImpl.class. The code is as simple as:
>> >>>
>> >>> @XmlRootElement(name = "Customer")
>> >>> public class CustomerImpl implements Customer {
>> >>>        private String name;
>> >>>        private EList<Order> orders;
>> >>>        public String getName() {
>> >>>                return name;
>> >>>        }
>> >>>        public void setName(String name) {
>> >>>                this.name = name;
>> >>>        }
>> >>>        public Order getOrder(String name) {
>> >>>                // return the order with the specified name
>> >>>                return null;
>> >>>        }
>> >>>        public void deleteOrder(String name) {
>> >>>                // remove the order with the specified name
>> >>>        }
>> >>> }
>> >>>
>> >>> @XmlRootElement(name = "Order")
>> >>> public class OrderImpl implements Order {
>> >>>        private String name;
>> >>>        private Customer customer;
>> >>>        public String getName() {
>> >>>                return name;
>> >>>        }
>> >>>        public void setName(String name) {
>> >>>                this.name = name;
>> >>>        }
>> >>>        public Customer getCustomer() {
>> >>>                return this.customer;
>> >>>        }
>> >>>        public void setCustomer(Customer c) {
>> >>>                this.customer = c;
>> >>>        }
>> >>> }
>> >>>
>> >>>
>> >>> The problem is that under "CustomerService" class, which contains a
>> >>> list of Customers and Orders, I have:
>> >>>
>> >>> @Path("/customerservice/')
>> >>> public class CustomerService {
>> >>>    ...
>> >>>    @POST
>> >>>    @Path("/customers/")
>> >>>    public Response addCustomer(Customer c) {
>> >>>        ......
>> >>>    }
>> >>>    ....
>> >>> }
>> >>>
>> >>> In this case, if I post a CustomerImpl object to
>> >>> "/customerservice/customers/", I have the error of "No message body
>> >>> reader has been found for request class Customer". If I change the
>> >>> function definition to be as follows, it works...
>> >>>    @POST
>> >>>    @Path("/customers/")
>> >>>    public Response addCustomer(CustomerImpl c) {
>> >>>        ......
>> >>>    }
>> >>>
>> >>> So, my first question is, is there a more elegant work-around such
>> >>> that "addCustomer" function would take "CustomerImpl" objects, even
>> >>> when the function parameter says "Customer c"?
>> >>>
>> >>> My second question is, let's say I want to post an "OrderImpl" object
>> >>> to "/customerservice/orders", but the OrderImpl object contains a
>> >>> reference to a customer. What is the best way to transfer the
>> >>> reference relationship between the client and the server? For some
>> >>> reason, the direct XML marshaling would ignore the reference.
>> >>>
>> >>
>> >>
>> >> Looks like it does not work because Order and Customer interfaces,
>> >> presumably generated by EMF, have no @XmlRootElement annotations
>> >> themselves.
>> >>
>> >> Adding these annotations to concrete implementations is problematic, as
>> >> you can add many components in EMF all the time. Some options to
>> >> consider:
>> >>
>> >> - I recall it is possible to add custom metadata to the EMF model. Is
>> >> it
>> >> possible to have @XmlRootElement added to the generated interfaces ?
>> >> - Explicitly configure CXF JAXBElementProvider and set it to use
>> >> JAXBElement internally - that should handle types such as Customer and
>> >> Order, see
>> >>
>> >> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-HandlingJAXBbeanswithoutXmlRootElementannotations
>> >>
>> >> Hope that helps
>> >>
>> >> Sergey
>> >>
>> >>>
>> >>> Thanks.
>> >>> -Simon
>> >>>
>> >>>
>> >>>
>> >>> On Thu, Apr 7, 2011 at 7:56 AM, Sergey Beryozkin
>> >>> <sb...@gmail.com>
>> >>> wrote:
>> >>> > Hi Simon
>> >>> >
>> >>> > On Wed, Apr 6, 2011 at 10:59 PM, Simon Chen <si...@gmail.com>
>> >>> > wrote:
>> >>> >>
>> >>> >> Hi all,
>> >>> >>
>> >>> >> I am trying to build a RESTful web service... In short, I am having
>> >>> >> trouble posting Java objects with member references from client
>> >>> >> side
>> >>> >> to server side.
>> >>> >>
>> >>> >> I have mostly followed the example under
>> >>> >> "apache-cxf-2.3.3/samples/jax_rs/basic". I have two major problems
>> >>> >> now...
>> >>> >>
>> >>> >> 1) Handle objects with references. For example, a customer may have
>> >>> >> a
>> >>> >> list of orders, and an order may be linked back to a customer. So,
>> >>> >> how
>> >>> >> can I (or indeed what is the best way to) post an "Order" object
>> >>> >> with
>> >>> >> a link to a "Customer" object to "/customerservice/orders"?
>> >>> >>
>> >>> >> 2) The example uses annotations like "XmlRootElement" to enable
>> >>> >> sort
>> >>> >> of automated conversioning from java objects to XML/json data. But
>> >>> >> this conversion seems to be broken when I add references into a
>> >>> >> class
>> >>> >> definition. For example, when I post an "Order" object to
>> >>> >> "/customerservice/orders", the server reports "No message body
>> >>> >> reader
>> >>> >> has been found for request class Order", (even though the customer
>> >>> >> ref
>> >>> >> is set to null).
>> >>> >>
>> >>> >
>> >>> > Is that Order class also annotated ? Can you post some sample
>> >>> > structures
>> >>> > showing what exactly you'd like to do ?
>> >>> >
>> >>> > Thanks, Sergey
>> >>> >
>> >>> >>
>> >>> >> Thanks.
>> >>> >> -Simon
>> >>> >
>> >>> >
>> >>> >
>> >>
>> >>
>> >>
>> >> --
>> >> Sergey Beryozkin
>> >>
>> >> Application Integration Division of Talend
>> >> http://sberyozkin.blogspot.com
>> >
>> >
>
>
>

Re: passing objects with reference in jax-rs

Posted by Sergey Beryozkin <sb...@gmail.com>.
On Thu, Apr 7, 2011 at 5:28 PM, Simon Chen <si...@gmail.com> wrote:

> Can you elaborate (or post a link) on this one?
>
> I am actually modifying the genmodel code (javajetinc files), such
> that genmodel would add @XmlRootElement tags automatically. The
> downside is that I don't know if I added enough of them, or indeed
> where I should add to...
>
> I don't recall the details, may be David B can advise something :-)

Cheers, Sergey


> Thanks a lot for your input. I will try them.
>
> -Simon
>
> On Thu, Apr 7, 2011 at 12:22 PM, Sergey Beryozkin <sb...@gmail.com>
> wrote:
> > Actually, another option is to add a custom JAX-RS provider which handles
> > Order/etc using the EMF itself (which will produce XMI - though it's a
> > complex XML indeed)
> >
> > Sergey
> >
> > On Thu, Apr 7, 2011 at 5:21 PM, Sergey Beryozkin <sb...@gmail.com>
> > wrote:
> >>
> >> Hi
> >>
> >> Please see comments inline
> >>
> >> On Thu, Apr 7, 2011 at 4:55 PM, Simon Chen <si...@gmail.com>
> wrote:
> >>>
> >>> I have some new findings...
> >>>
> >>> My class files are generated by EMF (ecore/genmodel).
> >>
> >> I guess it can help in time if CXF has an EMF binding or JAX-RS provider
> >>
> >>>
> >>> Thus, I have
> >>> both Customer.class and CustomerImpl.class. The code is as simple as:
> >>>
> >>> @XmlRootElement(name = "Customer")
> >>> public class CustomerImpl implements Customer {
> >>>        private String name;
> >>>        private EList<Order> orders;
> >>>        public String getName() {
> >>>                return name;
> >>>        }
> >>>        public void setName(String name) {
> >>>                this.name = name;
> >>>        }
> >>>        public Order getOrder(String name) {
> >>>                // return the order with the specified name
> >>>                return null;
> >>>        }
> >>>        public void deleteOrder(String name) {
> >>>                // remove the order with the specified name
> >>>        }
> >>> }
> >>>
> >>> @XmlRootElement(name = "Order")
> >>> public class OrderImpl implements Order {
> >>>        private String name;
> >>>        private Customer customer;
> >>>        public String getName() {
> >>>                return name;
> >>>        }
> >>>        public void setName(String name) {
> >>>                this.name = name;
> >>>        }
> >>>        public Customer getCustomer() {
> >>>                return this.customer;
> >>>        }
> >>>        public void setCustomer(Customer c) {
> >>>                this.customer = c;
> >>>        }
> >>> }
> >>>
> >>>
> >>> The problem is that under "CustomerService" class, which contains a
> >>> list of Customers and Orders, I have:
> >>>
> >>> @Path("/customerservice/')
> >>> public class CustomerService {
> >>>    ...
> >>>    @POST
> >>>    @Path("/customers/")
> >>>    public Response addCustomer(Customer c) {
> >>>        ......
> >>>    }
> >>>    ....
> >>> }
> >>>
> >>> In this case, if I post a CustomerImpl object to
> >>> "/customerservice/customers/", I have the error of "No message body
> >>> reader has been found for request class Customer". If I change the
> >>> function definition to be as follows, it works...
> >>>    @POST
> >>>    @Path("/customers/")
> >>>    public Response addCustomer(CustomerImpl c) {
> >>>        ......
> >>>    }
> >>>
> >>> So, my first question is, is there a more elegant work-around such
> >>> that "addCustomer" function would take "CustomerImpl" objects, even
> >>> when the function parameter says "Customer c"?
> >>>
> >>> My second question is, let's say I want to post an "OrderImpl" object
> >>> to "/customerservice/orders", but the OrderImpl object contains a
> >>> reference to a customer. What is the best way to transfer the
> >>> reference relationship between the client and the server? For some
> >>> reason, the direct XML marshaling would ignore the reference.
> >>>
> >>
> >>
> >> Looks like it does not work because Order and Customer interfaces,
> >> presumably generated by EMF, have no @XmlRootElement annotations
> themselves.
> >>
> >> Adding these annotations to concrete implementations is problematic, as
> >> you can add many components in EMF all the time. Some options to
> consider:
> >>
> >> - I recall it is possible to add custom metadata to the EMF model. Is it
> >> possible to have @XmlRootElement added to the generated interfaces ?
> >> - Explicitly configure CXF JAXBElementProvider and set it to use
> >> JAXBElement internally - that should handle types such as Customer and
> >> Order, see
> >>
> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-HandlingJAXBbeanswithoutXmlRootElementannotations
> >>
> >> Hope that helps
> >>
> >> Sergey
> >>
> >>>
> >>> Thanks.
> >>> -Simon
> >>>
> >>>
> >>>
> >>> On Thu, Apr 7, 2011 at 7:56 AM, Sergey Beryozkin <sberyozkin@gmail.com
> >
> >>> wrote:
> >>> > Hi Simon
> >>> >
> >>> > On Wed, Apr 6, 2011 at 10:59 PM, Simon Chen <si...@gmail.com>
> >>> > wrote:
> >>> >>
> >>> >> Hi all,
> >>> >>
> >>> >> I am trying to build a RESTful web service... In short, I am having
> >>> >> trouble posting Java objects with member references from client side
> >>> >> to server side.
> >>> >>
> >>> >> I have mostly followed the example under
> >>> >> "apache-cxf-2.3.3/samples/jax_rs/basic". I have two major problems
> >>> >> now...
> >>> >>
> >>> >> 1) Handle objects with references. For example, a customer may have
> a
> >>> >> list of orders, and an order may be linked back to a customer. So,
> how
> >>> >> can I (or indeed what is the best way to) post an "Order" object
> with
> >>> >> a link to a "Customer" object to "/customerservice/orders"?
> >>> >>
> >>> >> 2) The example uses annotations like "XmlRootElement" to enable sort
> >>> >> of automated conversioning from java objects to XML/json data. But
> >>> >> this conversion seems to be broken when I add references into a
> class
> >>> >> definition. For example, when I post an "Order" object to
> >>> >> "/customerservice/orders", the server reports "No message body
> reader
> >>> >> has been found for request class Order", (even though the customer
> ref
> >>> >> is set to null).
> >>> >>
> >>> >
> >>> > Is that Order class also annotated ? Can you post some sample
> >>> > structures
> >>> > showing what exactly you'd like to do ?
> >>> >
> >>> > Thanks, Sergey
> >>> >
> >>> >>
> >>> >> Thanks.
> >>> >> -Simon
> >>> >
> >>> >
> >>> >
> >>
> >>
> >>
> >> --
> >> Sergey Beryozkin
> >>
> >> Application Integration Division of Talend
> >> http://sberyozkin.blogspot.com
> >
> >
>

Re: passing objects with reference in jax-rs

Posted by Simon Chen <si...@gmail.com>.
Can you elaborate (or post a link) on this one?

I am actually modifying the genmodel code (javajetinc files), such
that genmodel would add @XmlRootElement tags automatically. The
downside is that I don't know if I added enough of them, or indeed
where I should add to...

Thanks a lot for your input. I will try them.

-Simon

On Thu, Apr 7, 2011 at 12:22 PM, Sergey Beryozkin <sb...@gmail.com> wrote:
> Actually, another option is to add a custom JAX-RS provider which handles
> Order/etc using the EMF itself (which will produce XMI - though it's a
> complex XML indeed)
>
> Sergey
>
> On Thu, Apr 7, 2011 at 5:21 PM, Sergey Beryozkin <sb...@gmail.com>
> wrote:
>>
>> Hi
>>
>> Please see comments inline
>>
>> On Thu, Apr 7, 2011 at 4:55 PM, Simon Chen <si...@gmail.com> wrote:
>>>
>>> I have some new findings...
>>>
>>> My class files are generated by EMF (ecore/genmodel).
>>
>> I guess it can help in time if CXF has an EMF binding or JAX-RS provider
>>
>>>
>>> Thus, I have
>>> both Customer.class and CustomerImpl.class. The code is as simple as:
>>>
>>> @XmlRootElement(name = "Customer")
>>> public class CustomerImpl implements Customer {
>>>        private String name;
>>>        private EList<Order> orders;
>>>        public String getName() {
>>>                return name;
>>>        }
>>>        public void setName(String name) {
>>>                this.name = name;
>>>        }
>>>        public Order getOrder(String name) {
>>>                // return the order with the specified name
>>>                return null;
>>>        }
>>>        public void deleteOrder(String name) {
>>>                // remove the order with the specified name
>>>        }
>>> }
>>>
>>> @XmlRootElement(name = "Order")
>>> public class OrderImpl implements Order {
>>>        private String name;
>>>        private Customer customer;
>>>        public String getName() {
>>>                return name;
>>>        }
>>>        public void setName(String name) {
>>>                this.name = name;
>>>        }
>>>        public Customer getCustomer() {
>>>                return this.customer;
>>>        }
>>>        public void setCustomer(Customer c) {
>>>                this.customer = c;
>>>        }
>>> }
>>>
>>>
>>> The problem is that under "CustomerService" class, which contains a
>>> list of Customers and Orders, I have:
>>>
>>> @Path("/customerservice/')
>>> public class CustomerService {
>>>    ...
>>>    @POST
>>>    @Path("/customers/")
>>>    public Response addCustomer(Customer c) {
>>>        ......
>>>    }
>>>    ....
>>> }
>>>
>>> In this case, if I post a CustomerImpl object to
>>> "/customerservice/customers/", I have the error of "No message body
>>> reader has been found for request class Customer". If I change the
>>> function definition to be as follows, it works...
>>>    @POST
>>>    @Path("/customers/")
>>>    public Response addCustomer(CustomerImpl c) {
>>>        ......
>>>    }
>>>
>>> So, my first question is, is there a more elegant work-around such
>>> that "addCustomer" function would take "CustomerImpl" objects, even
>>> when the function parameter says "Customer c"?
>>>
>>> My second question is, let's say I want to post an "OrderImpl" object
>>> to "/customerservice/orders", but the OrderImpl object contains a
>>> reference to a customer. What is the best way to transfer the
>>> reference relationship between the client and the server? For some
>>> reason, the direct XML marshaling would ignore the reference.
>>>
>>
>>
>> Looks like it does not work because Order and Customer interfaces,
>> presumably generated by EMF, have no @XmlRootElement annotations themselves.
>>
>> Adding these annotations to concrete implementations is problematic, as
>> you can add many components in EMF all the time. Some options to consider:
>>
>> - I recall it is possible to add custom metadata to the EMF model. Is it
>> possible to have @XmlRootElement added to the generated interfaces ?
>> - Explicitly configure CXF JAXBElementProvider and set it to use
>> JAXBElement internally - that should handle types such as Customer and
>> Order, see
>> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-HandlingJAXBbeanswithoutXmlRootElementannotations
>>
>> Hope that helps
>>
>> Sergey
>>
>>>
>>> Thanks.
>>> -Simon
>>>
>>>
>>>
>>> On Thu, Apr 7, 2011 at 7:56 AM, Sergey Beryozkin <sb...@gmail.com>
>>> wrote:
>>> > Hi Simon
>>> >
>>> > On Wed, Apr 6, 2011 at 10:59 PM, Simon Chen <si...@gmail.com>
>>> > wrote:
>>> >>
>>> >> Hi all,
>>> >>
>>> >> I am trying to build a RESTful web service... In short, I am having
>>> >> trouble posting Java objects with member references from client side
>>> >> to server side.
>>> >>
>>> >> I have mostly followed the example under
>>> >> "apache-cxf-2.3.3/samples/jax_rs/basic". I have two major problems
>>> >> now...
>>> >>
>>> >> 1) Handle objects with references. For example, a customer may have a
>>> >> list of orders, and an order may be linked back to a customer. So, how
>>> >> can I (or indeed what is the best way to) post an "Order" object with
>>> >> a link to a "Customer" object to "/customerservice/orders"?
>>> >>
>>> >> 2) The example uses annotations like "XmlRootElement" to enable sort
>>> >> of automated conversioning from java objects to XML/json data. But
>>> >> this conversion seems to be broken when I add references into a class
>>> >> definition. For example, when I post an "Order" object to
>>> >> "/customerservice/orders", the server reports "No message body reader
>>> >> has been found for request class Order", (even though the customer ref
>>> >> is set to null).
>>> >>
>>> >
>>> > Is that Order class also annotated ? Can you post some sample
>>> > structures
>>> > showing what exactly you'd like to do ?
>>> >
>>> > Thanks, Sergey
>>> >
>>> >>
>>> >> Thanks.
>>> >> -Simon
>>> >
>>> >
>>> >
>>
>>
>>
>> --
>> Sergey Beryozkin
>>
>> Application Integration Division of Talend
>> http://sberyozkin.blogspot.com
>
>

Re: passing objects with reference in jax-rs

Posted by Sergey Beryozkin <sb...@gmail.com>.
Actually, another option is to add a custom JAX-RS provider which handles
Order/etc using the EMF itself (which will produce XMI - though it's a
complex XML indeed)

Sergey

On Thu, Apr 7, 2011 at 5:21 PM, Sergey Beryozkin <sb...@gmail.com>wrote:

> Hi
>
> Please see comments inline
>
> On Thu, Apr 7, 2011 at 4:55 PM, Simon Chen <si...@gmail.com> wrote:
>
>> I have some new findings...
>>
>> My class files are generated by EMF (ecore/genmodel).
>
>
> I guess it can help in time if CXF has an EMF binding or JAX-RS provider
>
>
>> Thus, I have
>> both Customer.class and CustomerImpl.class. The code is as simple as:
>>
>> @XmlRootElement(name = "Customer")
>> public class CustomerImpl implements Customer {
>>        private String name;
>>        private EList<Order> orders;
>>        public String getName() {
>>                return name;
>>        }
>>        public void setName(String name) {
>>                this.name = name;
>>        }
>>        public Order getOrder(String name) {
>>                // return the order with the specified name
>>                return null;
>>        }
>>        public void deleteOrder(String name) {
>>                // remove the order with the specified name
>>        }
>> }
>>
>> @XmlRootElement(name = "Order")
>> public class OrderImpl implements Order {
>>        private String name;
>>        private Customer customer;
>>        public String getName() {
>>                return name;
>>        }
>>        public void setName(String name) {
>>                this.name = name;
>>        }
>>        public Customer getCustomer() {
>>                return this.customer;
>>        }
>>        public void setCustomer(Customer c) {
>>                this.customer = c;
>>        }
>> }
>>
>>
>> The problem is that under "CustomerService" class, which contains a
>> list of Customers and Orders, I have:
>>
>> @Path("/customerservice/')
>> public class CustomerService {
>>    ...
>>    @POST
>>    @Path("/customers/")
>>    public Response addCustomer(Customer c) {
>>        ......
>>    }
>>    ....
>> }
>>
>> In this case, if I post a CustomerImpl object to
>> "/customerservice/customers/", I have the error of "No message body
>> reader has been found for request class Customer". If I change the
>> function definition to be as follows, it works...
>>    @POST
>>    @Path("/customers/")
>>    public Response addCustomer(CustomerImpl c) {
>>        ......
>>    }
>>
>> So, my first question is, is there a more elegant work-around such
>> that "addCustomer" function would take "CustomerImpl" objects, even
>> when the function parameter says "Customer c"?
>>
>> My second question is, let's say I want to post an "OrderImpl" object
>> to "/customerservice/orders", but the OrderImpl object contains a
>> reference to a customer. What is the best way to transfer the
>> reference relationship between the client and the server? For some
>> reason, the direct XML marshaling would ignore the reference.
>>
>>
>
> Looks like it does not work because Order and Customer interfaces,
> presumably generated by EMF, have no @XmlRootElement annotations themselves.
>
> Adding these annotations to concrete implementations is problematic, as you
> can add many components in EMF all the time. Some options to consider:
>
> - I recall it is possible to add custom metadata to the EMF model. Is it
> possible to have @XmlRootElement added to the generated interfaces ?
> - Explicitly configure CXF JAXBElementProvider and set it to use
> JAXBElement internally - that should handle types such as Customer and
> Order, see
> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-HandlingJAXBbeanswithoutXmlRootElementannotations
>
> Hope that helps
>
> Sergey
>
>
>> Thanks.
>> -Simon
>>
>>
>>
>> On Thu, Apr 7, 2011 at 7:56 AM, Sergey Beryozkin <sb...@gmail.com>
>> wrote:
>> > Hi Simon
>> >
>> > On Wed, Apr 6, 2011 at 10:59 PM, Simon Chen <si...@gmail.com>
>> wrote:
>> >>
>> >> Hi all,
>> >>
>> >> I am trying to build a RESTful web service... In short, I am having
>> >> trouble posting Java objects with member references from client side
>> >> to server side.
>> >>
>> >> I have mostly followed the example under
>> >> "apache-cxf-2.3.3/samples/jax_rs/basic". I have two major problems
>> >> now...
>> >>
>> >> 1) Handle objects with references. For example, a customer may have a
>> >> list of orders, and an order may be linked back to a customer. So, how
>> >> can I (or indeed what is the best way to) post an "Order" object with
>> >> a link to a "Customer" object to "/customerservice/orders"?
>> >>
>> >> 2) The example uses annotations like "XmlRootElement" to enable sort
>> >> of automated conversioning from java objects to XML/json data. But
>> >> this conversion seems to be broken when I add references into a class
>> >> definition. For example, when I post an "Order" object to
>> >> "/customerservice/orders", the server reports "No message body reader
>> >> has been found for request class Order", (even though the customer ref
>> >> is set to null).
>> >>
>> >
>> > Is that Order class also annotated ? Can you post some sample structures
>> > showing what exactly you'd like to do ?
>> >
>> > Thanks, Sergey
>> >
>> >>
>> >> Thanks.
>> >> -Simon
>> >
>> >
>> >
>>
>
>
>
> --
> Sergey Beryozkin
>
> Application Integration Division of Talend <http://www.talend.com>
> http://sberyozkin.blogspot.com
>

Re: passing objects with reference in jax-rs

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

Please see comments inline

On Thu, Apr 7, 2011 at 4:55 PM, Simon Chen <si...@gmail.com> wrote:

> I have some new findings...
>
> My class files are generated by EMF (ecore/genmodel).


I guess it can help in time if CXF has an EMF binding or JAX-RS provider


> Thus, I have
> both Customer.class and CustomerImpl.class. The code is as simple as:
>
> @XmlRootElement(name = "Customer")
> public class CustomerImpl implements Customer {
>        private String name;
>        private EList<Order> orders;
>        public String getName() {
>                return name;
>        }
>        public void setName(String name) {
>                this.name = name;
>        }
>        public Order getOrder(String name) {
>                // return the order with the specified name
>                return null;
>        }
>        public void deleteOrder(String name) {
>                // remove the order with the specified name
>        }
> }
>
> @XmlRootElement(name = "Order")
> public class OrderImpl implements Order {
>        private String name;
>        private Customer customer;
>        public String getName() {
>                return name;
>        }
>        public void setName(String name) {
>                this.name = name;
>        }
>        public Customer getCustomer() {
>                return this.customer;
>        }
>        public void setCustomer(Customer c) {
>                this.customer = c;
>        }
> }
>
>
> The problem is that under "CustomerService" class, which contains a
> list of Customers and Orders, I have:
>
> @Path("/customerservice/')
> public class CustomerService {
>    ...
>    @POST
>    @Path("/customers/")
>    public Response addCustomer(Customer c) {
>        ......
>    }
>    ....
> }
>
> In this case, if I post a CustomerImpl object to
> "/customerservice/customers/", I have the error of "No message body
> reader has been found for request class Customer". If I change the
> function definition to be as follows, it works...
>    @POST
>    @Path("/customers/")
>    public Response addCustomer(CustomerImpl c) {
>        ......
>    }
>
> So, my first question is, is there a more elegant work-around such
> that "addCustomer" function would take "CustomerImpl" objects, even
> when the function parameter says "Customer c"?
>
> My second question is, let's say I want to post an "OrderImpl" object
> to "/customerservice/orders", but the OrderImpl object contains a
> reference to a customer. What is the best way to transfer the
> reference relationship between the client and the server? For some
> reason, the direct XML marshaling would ignore the reference.
>
>

Looks like it does not work because Order and Customer interfaces,
presumably generated by EMF, have no @XmlRootElement annotations themselves.

Adding these annotations to concrete implementations is problematic, as you
can add many components in EMF all the time. Some options to consider:

- I recall it is possible to add custom metadata to the EMF model. Is it
possible to have @XmlRootElement added to the generated interfaces ?
- Explicitly configure CXF JAXBElementProvider and set it to use JAXBElement
internally - that should handle types such as Customer and Order, see
http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-HandlingJAXBbeanswithoutXmlRootElementannotations

Hope that helps

Sergey


> Thanks.
> -Simon
>
>
>
> On Thu, Apr 7, 2011 at 7:56 AM, Sergey Beryozkin <sb...@gmail.com>
> wrote:
> > Hi Simon
> >
> > On Wed, Apr 6, 2011 at 10:59 PM, Simon Chen <si...@gmail.com>
> wrote:
> >>
> >> Hi all,
> >>
> >> I am trying to build a RESTful web service... In short, I am having
> >> trouble posting Java objects with member references from client side
> >> to server side.
> >>
> >> I have mostly followed the example under
> >> "apache-cxf-2.3.3/samples/jax_rs/basic". I have two major problems
> >> now...
> >>
> >> 1) Handle objects with references. For example, a customer may have a
> >> list of orders, and an order may be linked back to a customer. So, how
> >> can I (or indeed what is the best way to) post an "Order" object with
> >> a link to a "Customer" object to "/customerservice/orders"?
> >>
> >> 2) The example uses annotations like "XmlRootElement" to enable sort
> >> of automated conversioning from java objects to XML/json data. But
> >> this conversion seems to be broken when I add references into a class
> >> definition. For example, when I post an "Order" object to
> >> "/customerservice/orders", the server reports "No message body reader
> >> has been found for request class Order", (even though the customer ref
> >> is set to null).
> >>
> >
> > Is that Order class also annotated ? Can you post some sample structures
> > showing what exactly you'd like to do ?
> >
> > Thanks, Sergey
> >
> >>
> >> Thanks.
> >> -Simon
> >
> >
> >
>



-- 
Sergey Beryozkin

Application Integration Division of Talend <http://www.talend.com>
http://sberyozkin.blogspot.com

Re: passing objects with reference in jax-rs

Posted by Simon Chen <si...@gmail.com>.
I have some new findings...

My class files are generated by EMF (ecore/genmodel). Thus, I have
both Customer.class and CustomerImpl.class. The code is as simple as:

@XmlRootElement(name = "Customer")
public class CustomerImpl implements Customer {
	private String name;
	private EList<Order> orders;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Order getOrder(String name) {
		// return the order with the specified name
		return null;
	}
	public void deleteOrder(String name) {
		// remove the order with the specified name
	}
}

@XmlRootElement(name = "Order")
public class OrderImpl implements Order {
	private String name;
	private Customer customer;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Customer getCustomer() {
		return this.customer;
	}
	public void setCustomer(Customer c) {
		this.customer = c;
	}
}


The problem is that under "CustomerService" class, which contains a
list of Customers and Orders, I have:

@Path("/customerservice/')
public class CustomerService {
    ...
    @POST
    @Path("/customers/")
    public Response addCustomer(Customer c) {
        ......
    }
    ....
}

In this case, if I post a CustomerImpl object to
"/customerservice/customers/", I have the error of "No message body
reader has been found for request class Customer". If I change the
function definition to be as follows, it works...
    @POST
    @Path("/customers/")
    public Response addCustomer(CustomerImpl c) {
        ......
    }

So, my first question is, is there a more elegant work-around such
that "addCustomer" function would take "CustomerImpl" objects, even
when the function parameter says "Customer c"?

My second question is, let's say I want to post an "OrderImpl" object
to "/customerservice/orders", but the OrderImpl object contains a
reference to a customer. What is the best way to transfer the
reference relationship between the client and the server? For some
reason, the direct XML marshaling would ignore the reference.

Thanks.
-Simon



On Thu, Apr 7, 2011 at 7:56 AM, Sergey Beryozkin <sb...@gmail.com> wrote:
> Hi Simon
>
> On Wed, Apr 6, 2011 at 10:59 PM, Simon Chen <si...@gmail.com> wrote:
>>
>> Hi all,
>>
>> I am trying to build a RESTful web service... In short, I am having
>> trouble posting Java objects with member references from client side
>> to server side.
>>
>> I have mostly followed the example under
>> "apache-cxf-2.3.3/samples/jax_rs/basic". I have two major problems
>> now...
>>
>> 1) Handle objects with references. For example, a customer may have a
>> list of orders, and an order may be linked back to a customer. So, how
>> can I (or indeed what is the best way to) post an "Order" object with
>> a link to a "Customer" object to "/customerservice/orders"?
>>
>> 2) The example uses annotations like "XmlRootElement" to enable sort
>> of automated conversioning from java objects to XML/json data. But
>> this conversion seems to be broken when I add references into a class
>> definition. For example, when I post an "Order" object to
>> "/customerservice/orders", the server reports "No message body reader
>> has been found for request class Order", (even though the customer ref
>> is set to null).
>>
>
> Is that Order class also annotated ? Can you post some sample structures
> showing what exactly you'd like to do ?
>
> Thanks, Sergey
>
>>
>> Thanks.
>> -Simon
>
>
>

Re: passing objects with reference in jax-rs

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

On Wed, Apr 6, 2011 at 10:59 PM, Simon Chen <si...@gmail.com> wrote:

> Hi all,
>
> I am trying to build a RESTful web service... In short, I am having
> trouble posting Java objects with member references from client side
> to server side.
>
> I have mostly followed the example under
> "apache-cxf-2.3.3/samples/jax_rs/basic". I have two major problems
> now...
>
> 1) Handle objects with references. For example, a customer may have a
> list of orders, and an order may be linked back to a customer. So, how
> can I (or indeed what is the best way to) post an "Order" object with
> a link to a "Customer" object to "/customerservice/orders"?
>
> 2) The example uses annotations like "XmlRootElement" to enable sort
> of automated conversioning from java objects to XML/json data. But
> this conversion seems to be broken when I add references into a class
> definition. For example, when I post an "Order" object to
> "/customerservice/orders", the server reports "No message body reader
> has been found for request class Order", (even though the customer ref
> is set to null).
>
>
Is that Order class also annotated ? Can you post some sample structures
showing what exactly you'd like to do ?

Thanks, Sergey


> Thanks.
> -Simon
>