0

There is an object like this (more than one field, but just one for this ex)

public class MyObject{
  private String objString;

  public String getObjString(){
   return objString;
  }

 public void setObjString(String str){
  this.objString = str;
 }
}

and a wrapper for it to take multiple

public class MyObjects{
 private List<MyObject> objects;
 ... getters and setters for list...
}

and an endpoint like this

@GetMapping("/sample")
public ResponseEntity<String> sampleEndpoint(MyObjects objs){...}

What should I be doing to send it properly? I have tried making a mock model of it and sending it over as a request param but that is not working. I am able to hit the endpoint in the browser if I do a url like

'/sample?objs%5B0%5D.objString=test&objs%5B1%5D.objString=test1'

but am not sure what the best method to do this in angular is.

  • Obviously a post is better. But did you try to do a JSON.stringify on the object? – MikeOne Oct 25 '21 at 22:04
  • does it make sense to post if the goal is to get data back? I have not tried it, I will try. – stackunderflow123 Oct 25 '21 at 22:29
  • GET requests *can* have a body, but that's very unconventional. A POST request is intended to create data, PUT/PATCH is to update, etc. A way you can send the object through the querystring is convert it to base64 first, but the endpoint would have to decode it. – Brandon Taylor Oct 25 '21 at 22:40

0 Answers0