On Tuesday, June 12, 2012 12:24:59 PM Danny Sinang wrote:
> Hi David,
> 
> Thanks for the info, but my colleague tells me the domain object we're
> using is in a different project.
> 
> We're trying to avoid having to put a dependency on CXF in that project,
> so our option now would be to create a copy of that domain object in our
> project and then apply the propOrder property.
> 
> Problem is, copying that object (which can contain thousands of rows of
> data) can be expensive.
> 
> Is there a way to tell CXF to just follow / honor the order of the
> properties in the source domain object ?

No, because in Java, the "order" of the properties is not recorded anywhere.   
Each Java compiler can put the methods into the .class file in any order 
they want.   Also, at runtime, the returned array from things like 
getMethods and getFields can be in any order the runtime wants.   There are 
no guarantees.    For example, the IBM JDK is notorious for returning them 
in the exact REVERSE order than the Sun JDK.   The new Java7 jdk seems to 
use a more "random" order.   This is one of the most common issue when 
porting JUnit tests from one JDK to another.   If you have multiple @Test 
annotated methods in a class that DON'T properly cleanup and thus leave side 
effects that other tests may rely on, those tests tend to randomly fail on 
Java7.

Dan



> 
> Regards,
> Danny
> 
> On Tue, Jun 12, 2012 at 12:11 PM, KARR, DAVID <[email protected]> wrote:
> > > -----Original Message-----
> > > From: Danny Sinang [mailto:[email protected]]
> > > Sent: Tuesday, June 12, 2012 9:04 AM
> > > To: [email protected]
> > > Subject: REST service returns elements in unexpected order
> > > 
> > > Hello,
> > > 
> > > We're using CXF version 2.6.1 and I noticed where returning results in
> > > an
> > > order that doesn't match the order in which our properties were
> > > defined
> > > in
> > > the source Java object.
> > > 
> > > For example, our Java object has the following properties :
> > > 
> > > private String trustedPartnerLogId;
> > > private ModuleLogEnum module;
> > > 
> > >  private OperationLogEnum operation;
> > > 
> > > private Long trustedPartnerId;
> > > private String customerId;
> > > 
> > >  private String sessionId;
> > > 
> > > private String dateCreated;
> > > 
> > > But the JSON output from the webservice call to CXF generates this :
> > >          "operation": "TPO_PAGE_SESSION_CLOSE",
> > >          "sessionId": "wf56m3mnxhch",
> > >          "dateCreated": "2012-06-11T18:09:24.527935-04:00",
> > >          "trustedPartnerId": 1014582732321112322,
> > >          "customerId": "9876500005",
> > >          "relatedAsset": null,
> > >          "trustedPartnerLogId":
> > >          "10fca7fb-d887-64b7-d63b-3315be395118",
> > >          "module": "TPM_BOOK",
> > > 
> > > The relevant code is shown below.
> > > 
> > > Any idea what I missed ? Is there a config setting that I can use to
> > > control the element order ?
> > 
> > This is done with the "propOrder" property in the @XmlType annotation on
> > your domain objects.  This is a list property, which specifies the names
> > of the properties in your type, implicitly defining their order by the
> > order in the list property.
-- 
Daniel Kulp
[email protected] - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com

Reply via email to