How to send (or maybe it's not possible?) complex object with file in Postman
My object:
class Client {
private String clientName;
private Platform platform;
}
class Platform {
private String android;
private String ios;
}
My Controller class:
@PostMapping(value = "/evaluate", produces = "application/json")
public ResponseEntity<ServerResponse> sendEvaluateForm(Client client,
@RequestParam(value = "files", required = false) MultipartFile files)
{
return new ResponseEntity<>(HttpStatus.OK);
}
That's how I am sending request in postman:
It work's when I pass "clientName" which is basic field in Client. But I have no idea, how to pass Platform object. I tried to pass in key: platform and in value: {"android" : "asd", "ios" : "xxx"} But i only got BadRequest(400)
With Postman you can build a request containing Files and Object at the same time.
Result expected as backend req.body:
{ street: '69 Pinapple street', city: 'Apple', zip: 6969, country: 'Pen' }
You can try send your client data as a plain string and parse it on the controller side.
@PostMapping(value = "/evaluate", produces = "application/json")
public ResponseEntity<?> sendEvaluateForm(@RequestParam ("client") String client,
@RequestParam(value = "files", required = false) MultipartFile files) throws IOException {
ObjectMapper mapper = new ObjectMapper();
Client clientobject = mapper.readValue(client, Client.class);
return ResponseEntity.ok().build();
}
And the postman request:
And your POJO classes:
class Client {
private String clientName;
private Platform platform;
public String getClientName() {
return clientName;
}
public void setClientName(String clientName) {
this.clientName = clientName;
}
public Platform getPlatform() {
return platform;
}
public void setPlatform(Platform platform) {
this.platform = platform;
}
}
class Platform {
private String android;
private String ios;
public String getAndroid() {
return android;
}
public void setAndroid(String android) {
this.android = android;
}
public String getIos() {
return ios;
}
public void setIos(String ios) {
this.ios = ios;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With