Postman form-data sending complex object with file












1















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:
enter image description here



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)










share|improve this question




















  • 2





    I don't think it's possible to send both a JSON payload AND form data at the same time. You could embed the JSON as part of the form, but I think you'll need to do the unmarshalling manually in that case. I'm not entirely sure though, so perhaps someone with a bit more Spring Web experience could correct me (I generally stick to JAX-RS)

    – Jeroen Steenbeeke
    Aug 10 '18 at 8:44











  • Thank you for your response. I think you may be right. I tried to do this in in few different ways, but none of this worked (my friend is sending me this form+file in JS). I could get this form in 1 object only with basic values, but it's pretty big (about 100fields) that's why I wanted to have it in seperate objects. But if I don't find the way how to send JSON+file I guess I will have to stick with that.

    – Moler
    Aug 10 '18 at 8:50
















1















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:
enter image description here



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)










share|improve this question




















  • 2





    I don't think it's possible to send both a JSON payload AND form data at the same time. You could embed the JSON as part of the form, but I think you'll need to do the unmarshalling manually in that case. I'm not entirely sure though, so perhaps someone with a bit more Spring Web experience could correct me (I generally stick to JAX-RS)

    – Jeroen Steenbeeke
    Aug 10 '18 at 8:44











  • Thank you for your response. I think you may be right. I tried to do this in in few different ways, but none of this worked (my friend is sending me this form+file in JS). I could get this form in 1 object only with basic values, but it's pretty big (about 100fields) that's why I wanted to have it in seperate objects. But if I don't find the way how to send JSON+file I guess I will have to stick with that.

    – Moler
    Aug 10 '18 at 8:50














1












1








1








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:
enter image description here



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)










share|improve this question
















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:
enter image description here



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)







java spring file-upload postman






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 10 '18 at 8:51









jreznot

1,26911835




1,26911835










asked Aug 10 '18 at 8:31









MolerMoler

23710




23710








  • 2





    I don't think it's possible to send both a JSON payload AND form data at the same time. You could embed the JSON as part of the form, but I think you'll need to do the unmarshalling manually in that case. I'm not entirely sure though, so perhaps someone with a bit more Spring Web experience could correct me (I generally stick to JAX-RS)

    – Jeroen Steenbeeke
    Aug 10 '18 at 8:44











  • Thank you for your response. I think you may be right. I tried to do this in in few different ways, but none of this worked (my friend is sending me this form+file in JS). I could get this form in 1 object only with basic values, but it's pretty big (about 100fields) that's why I wanted to have it in seperate objects. But if I don't find the way how to send JSON+file I guess I will have to stick with that.

    – Moler
    Aug 10 '18 at 8:50














  • 2





    I don't think it's possible to send both a JSON payload AND form data at the same time. You could embed the JSON as part of the form, but I think you'll need to do the unmarshalling manually in that case. I'm not entirely sure though, so perhaps someone with a bit more Spring Web experience could correct me (I generally stick to JAX-RS)

    – Jeroen Steenbeeke
    Aug 10 '18 at 8:44











  • Thank you for your response. I think you may be right. I tried to do this in in few different ways, but none of this worked (my friend is sending me this form+file in JS). I could get this form in 1 object only with basic values, but it's pretty big (about 100fields) that's why I wanted to have it in seperate objects. But if I don't find the way how to send JSON+file I guess I will have to stick with that.

    – Moler
    Aug 10 '18 at 8:50








2




2





I don't think it's possible to send both a JSON payload AND form data at the same time. You could embed the JSON as part of the form, but I think you'll need to do the unmarshalling manually in that case. I'm not entirely sure though, so perhaps someone with a bit more Spring Web experience could correct me (I generally stick to JAX-RS)

– Jeroen Steenbeeke
Aug 10 '18 at 8:44





I don't think it's possible to send both a JSON payload AND form data at the same time. You could embed the JSON as part of the form, but I think you'll need to do the unmarshalling manually in that case. I'm not entirely sure though, so perhaps someone with a bit more Spring Web experience could correct me (I generally stick to JAX-RS)

– Jeroen Steenbeeke
Aug 10 '18 at 8:44













Thank you for your response. I think you may be right. I tried to do this in in few different ways, but none of this worked (my friend is sending me this form+file in JS). I could get this form in 1 object only with basic values, but it's pretty big (about 100fields) that's why I wanted to have it in seperate objects. But if I don't find the way how to send JSON+file I guess I will have to stick with that.

– Moler
Aug 10 '18 at 8:50





Thank you for your response. I think you may be right. I tried to do this in in few different ways, but none of this worked (my friend is sending me this form+file in JS). I could get this form in 1 object only with basic values, but it's pretty big (about 100fields) that's why I wanted to have it in seperate objects. But if I don't find the way how to send JSON+file I guess I will have to stick with that.

– Moler
Aug 10 '18 at 8:50












1 Answer
1






active

oldest

votes


















1














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:



enter image description here



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





share|improve this answer


























  • WoW, I didn't think about that idea. THANK YOU.

    – Moler
    Aug 10 '18 at 9:07











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51782257%2fpostman-form-data-sending-complex-object-with-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














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:



enter image description here



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





share|improve this answer


























  • WoW, I didn't think about that idea. THANK YOU.

    – Moler
    Aug 10 '18 at 9:07
















1














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:



enter image description here



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





share|improve this answer


























  • WoW, I didn't think about that idea. THANK YOU.

    – Moler
    Aug 10 '18 at 9:07














1












1








1







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:



enter image description here



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





share|improve this answer















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:



enter image description here



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






share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 10 '18 at 13:46

























answered Aug 10 '18 at 9:03









Marcin BukowieckiMarcin Bukowiecki

30226




30226













  • WoW, I didn't think about that idea. THANK YOU.

    – Moler
    Aug 10 '18 at 9:07



















  • WoW, I didn't think about that idea. THANK YOU.

    – Moler
    Aug 10 '18 at 9:07

















WoW, I didn't think about that idea. THANK YOU.

– Moler
Aug 10 '18 at 9:07





WoW, I didn't think about that idea. THANK YOU.

– Moler
Aug 10 '18 at 9:07




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51782257%2fpostman-form-data-sending-complex-object-with-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'