如何强制Jersey生成指定的JSON响应

时间:2014-02-21 11:45:54

标签: json rest jersey jax-rs

所以,我已经开始在我们的REST服务应用程序中使用Jersey作为JAX-RS的实现,我遇到了一个奇怪的问题。我们已获得如下标准回复:

"Outer":
   {
       "agencyPercentagePayment": "80",
       "agencyProviderPaymentAmount": "140.00",
       "benCoDtls":
       {
           "benCode": "String1",
           "fullName": "String2",
           "id": "String3",
           "title": "String4"
       },
       "levelOfCare": "Full-Time",
       "paymentDate": "2014-02-19T15:20",
       "titleInfo":
       {
           "benAmt": "140.0",
           "benDesc": "AAAA",
           "subTitle": "aaaa",
           "title": "String"
       },
       "units": "10"
   }

但是,泽西岛提供商生成的JSON会生成如下的仲裁响应:

"Outer":
   {
       "agencyProviderPaymentAmount": "140.00",
       "benCoDtls": 
       {
           "benCode": "String1",
           "fullName": "String2",
           "id": "String3",
           "title": "String4"
       },
       "agencyPercentagePayment": "80",
       "titleInfo":
       {
           "benAmt": "140.0",
           "benDesc": "AAAA",
           "subTitle": "aaaa",
           "title": "String"
       },
       "paymentDate": "2014-02-19T15:20",
       "levelOfCare": "Full-Time",
       "units": "10"
   }

如上所述,响应期望agencyPercentagePayment在完成benCoDtls数组之后作为第一个元素的外部levelOfCare和在levelOfCare之后的paymentDate,但是响应是不同的,如你所见。

如何执行泽西杰克逊提供商生成的响应的任何建议?如果需要,我可以共享Java类。

由于

1 个答案:

答案 0 :(得分:2)

您应该能够使用@XmlType注释解决此问题:

 @XmlType(propOrder={"agencyPercentagePayment", "agencyProviderPaymentAmount" , ... })
 @XmlRootElement
 public class Outer {
 ....
 }