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 <[email protected]> wrote: > Hi > > On Fri, Apr 8, 2011 at 5:08 AM, Simon Chen <[email protected]> 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 <[email protected]> > wrote: >> >> >> On Thu, Apr 7, 2011 at 5:28 PM, Simon Chen <[email protected]> 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 <[email protected]> >>> 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 <[email protected]> >>> > wrote: >>> >> >>> >> Hi >>> >> >>> >> Please see comments inline >>> >> >>> >> On Thu, Apr 7, 2011 at 4:55 PM, Simon Chen <[email protected]> >>> >> 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: >>> >> > > >
