4

I have two controllers in my micro service both are POST and accepts Request body as JSON, one is working fine and another one's JSON input from some othet team and it is with root class name , so I need to write custom object mapper for this later controller, could you please guys help,

please find the codes below,

@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";
    }
}

and the sample json is as follows,

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

UpdateEMDRequest,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;

}

So this json is not parsed properly and updateEMDRequest's properties are null always.

nallskarthi
  • 281
  • 1
  • 8
  • 19

0 Answers0