如何为特定的弹簧支架控制器添加自定义objectMapper

时间:2016-05-05 06:41:21

标签: json spring spring-restcontroller objectmapper

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

请找到以下代码,

var updatedStyle = el.getAttribute('style').replace(/(_)(\d)/, "$12");
el.setAttribute('style', updatedStyle);

和样本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";
    }
}

UpdateEMDRequest,JAVA

{
   "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"
                  ]
               }
            }
         }
      ]
   }
}

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

0 个答案:

没有答案