0

code for the controller

    @RequestMapping(value = "/second", method = RequestMethod.POST, 
    consumes = "application/json")
    @ResponseBody
    public void test(@RequestBody RegistrationRequest 
    registrationRequest) 
    {
       System.out.println(registrationRequest.toString());
    }

POJO

    @Data
    @JsonDeserialize(using = Base64Deserializer.class)
    public class RegistrationRequest {
       @JsonProperty("payment-method-details")
       public PaymentMethodDetails paymentMethodDetails;
       @JsonProperty("customer-details")
       public CustomerDetails customerDetails;
    }

CustomerDetails, PaymentMethodDetails are POJO of their own. I am very new to the Spring MVC concepts, and this is all I have figured out till now but while making the post request from the Postman, it isn't working. What is wrong that I am doing?

I can not maneuver anything how the request is going to come.

Using Base64 deserialiser

Decode base64 encoded JSON to POJO with jackson and spring-boot

James Z
  • 12,209
  • 10
  • 24
  • 44
Crosk Cool
  • 664
  • 2
  • 12
  • 27

1 Answers1

0

It is not clear from the question, about the desired format of the request.

Above code should work fine with a request like this :

curl -X POST "http://myhost:port/rootPath/second/" -d '{"payment-method-details":"eyJwYXltZW50TWV0aG9kRGV0YWlsc1ZhcjEiOiJzb21lIHRleHQiLCJwYXltZW50TWV0aG9kRGV0YWlsc1ZhcjIiOiJzb21lIHRleHQyIn0=", "customer-details":"eyJjdXN0b21lckRldGFpbHNWYXIxIjoic29tZSB0ZXh0IiwiY3VzdG9tZXJEZXRhaWxzVmFyMiI6InNvbWUgdGV4dDIifQ=="}'

This will get the above code working and prints the output.

Note, here eyJjdXN0b21lckRldGFpbHNWYXIxIjoic29tZSB0ZXh0IiwiY3VzdG9tZXJEZXRhaWxzVmFyMiI6InNvbWUgdGV4dDIifQ== decodes to {"customerDetailsVar1":"some text","customerDetailsVar2":"some text2"} in base64 format, similar is the case for other variable.

Saheb
  • 1,392
  • 3
  • 13
  • 33