0
@Secured({ "ROLE_CLIENT", "ROLE_TRUSTED_CLIENT", "ROLE_CUSTOMERMANAGERGROUP","ROLE_CUSTOMERGROUP" })
@PostMapping(value = "/create", consumes ={ MediaType.MULTIPART_FORM_DATA_VALUE , MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
@ApiOperation(nickname = "SaveCompanyDetail", value = " Saves Company Detail", notes = "Saves Company Detail requires the WsDTO with the customer data.", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiBaseSiteIdParam
public String createCompanyDetail(@RequestPart(value = "companyDetails", required = false) final CompanyDetailsData dataObject,  @RequestPart(value = "companyLogo", required = false) final MultipartFile companyLogo) {
    try {
        ///getting dataObject all the time
    } catch (Exception ex) {
        LOG.error("createCompanyDetail :: ",ex.getMessage());
        return FAILED;
    }
    return SUCCESS;
}

public class CompanyDetailsData implements Serializable {

private static final long serialVersionUID = 1L;
private String id;
private String email;
private String title;
private String phoneNumber;

}

Always getting null in dataObject object in the controller class.

Payload: { "id": "123", "email": "string", "phoneNumber": "string", "title": "title test" }

Post man : enter image description here

Tusker
  • 15
  • 4

1 Answers1

0

Try something like this using Curl:

curl --location --request POST 'https://example.com/create' --form 'companyDetails={"id": "123", "email": "string", "phoneNumber": "string", "title": "title test"}' --form 'companyLogo=@/path/to/image.png' --header 'Content-Type: multipart/form-data'

or just specify the Content-Type in Postman, it's possible that you get null because you missed it. Your controller can consume 3 different types of params including JSON, XML, and multipart/form-date. Try to be explicit about what type of request you gonna send.

you can use this thread as reference: How to send data as @RequestPart in the postman