You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Danny Sinang <d....@gmail.com> on 2012/06/12 18:04:15 UTC

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 ?

Regards,
Danny

public Response searchLogs(HttpServletRequest request, String tpID, Boolean
returnResults,
String groupBy, MeasureEnum measure, FilterTrustedPartnerLogs filter,
PortalPageVO page)
 {
ResponseBuilder builder = ServiceUtils.toErrorResponse(request,
ErrorCodesEnum.UNABLE_TO_SEARCH_LOGS);
 if ((page == null) || (page!=null && page.getLimit() == 0)) {
builder = ServiceUtils.toErrorResponse(request,
ErrorCodesEnum.REQUEST_LIMIT_MUST_BE_SPECIFIED);
 } else if ((filter == null || StringUtils.isEmpty(filter.getStartDate())
|| StringUtils.isEmpty(filter.getEndDate()))) {
builder = ServiceUtils.toErrorResponse(request,
ErrorCodesEnum.STARTDATE_AND_ENDDATE_MUST_BE_SPECIFIED);
 } else {
try {
filter.setTrustedPartnerId(Long.valueOf(tpID));
 builder = Response.ok().entity(this.analyticsManager.searchLogs(filter,
page, returnResults, groupBy, measure));
 } catch (Exception e) {
this.emailUtils.createEmailThenSend("AnalyticsWebservicesManager",
"searchLogs", tpID, null, e);
 }
}
return builder.build();
 }

Re: REST service returns elements in unexpected order

Posted by Daniel Kulp <dk...@apache.org>.
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 <dk...@att.com> wrote:
> > > -----Original Message-----
> > > From: Danny Sinang [mailto:d.sinang@gmail.com]
> > > Sent: Tuesday, June 12, 2012 9:04 AM
> > > To: users@cxf.apache.org
> > > 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
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com

Re: REST service returns elements in unexpected order

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi, may be you can try a jackson provider

Cheers, Sergey
On 12/06/12 17:24, 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 ?
>
> Regards,
> Danny
>
> On Tue, Jun 12, 2012 at 12:11 PM, KARR, DAVID<dk...@att.com>  wrote:
>
>>> -----Original Message-----
>>> From: Danny Sinang [mailto:d.sinang@gmail.com]
>>> Sent: Tuesday, June 12, 2012 9:04 AM
>>> To: users@cxf.apache.org
>>> 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.
>>
>>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: REST service returns elements in unexpected order

Posted by Danny Sinang <d....@gmail.com>.
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 ?

Regards,
Danny

On Tue, Jun 12, 2012 at 12:11 PM, KARR, DAVID <dk...@att.com> wrote:

> > -----Original Message-----
> > From: Danny Sinang [mailto:d.sinang@gmail.com]
> > Sent: Tuesday, June 12, 2012 9:04 AM
> > To: users@cxf.apache.org
> > 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.
>
>

RE: REST service returns elements in unexpected order

Posted by "KARR, DAVID" <dk...@att.com>.
> -----Original Message-----
> From: Danny Sinang [mailto:d.sinang@gmail.com]
> Sent: Tuesday, June 12, 2012 9:04 AM
> To: users@cxf.apache.org
> 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.