4

我的微服务中有两个控制器都是 POST 并接受请求正文为 JSON,一个工作正常,另一个是来自其他团队的 JSON 输入,它是根类名称,所以我需要稍后为此编写自定义对象映射器控制器,请你们帮忙,

请在下面找到代码,

@RestController
@Slf4j
public class Controller2 {
    @RequestMapping(value = "/some/update", method = RequestMethod.POST)
    public String updateEmd(@RequestBody final UpdateEMDRequest updateEMDRequest) throws JsonProcessingException {

            updateEMDRequest.getBookingReference()); // null now
            return "success";
    }
}

示例json如下,

{
   "UpdateEMDRequest":{
      "TransactionStatus":"SUCCESS",
      "UniqueTransactionReference":"046060420",
      "PreAuthReference":"040520420",
      "BookingReference":"8PJ",
      "CarrierCode":"AS",
      "TransactionMode":"Batch",
      "CallBackUrl":"www.test.com/op/update",
      "Offers":[
         {
            "Offer":{
               "traveler":{
                  "firstName":"AHONY",
                  "surname":"DNEN",
                  "EMD":[
                     "081820470"
                  ]
               }
            }
         }
      ]
   }
}

更新EMDRequest,java

@JsonInclude(Include.NON_NULL)
public class UpdateEMDRequest {
    @JsonProperty("UniqueTransactionReference")
    private String uniqueTransactionReference;
    @JsonProperty("TransactionStatus")
    private String transactionStatus;
    @JsonProperty("PreAuthReference")
    private String preAuthReference;
    @JsonProperty("BookingReference")
    private String bookingReference;
    @JsonProperty("CarrierCode")
    private String carrierCode;
    @JsonProperty("TransactionMode")
    private String transactionMode;
    @JsonProperty("CallBackUrl")
    private String callBackUrl;
    @JsonProperty("Offers")
    private List<Offers> offers;

}

所以这个 json 没有被正确解析,并且 updateEMDRequest 的属性总是为空。

4

0 回答 0