0

I'm trying to make a post request but I'm getting a strange error.

No primary or default constructor found for interface java.util.List

clients,accounts and transactions are normal arrays (typescript doesn't have list) but this should work i guess.

Do I really need to get Client[],etc... and then convert to list in the controller? doesn't make much sense.

Code:

Request

createEnvironment(environment,clients,accounts,transactions) {
const params = new HttpParams()
  .set("environment", environment)
  .set("clients", clients)
  .set("accounts", accounts)
  .set("transactions",transactions)
  .set("isCloned", "false");

console.log(params);

return this._http.post<any>(RequestProperties.baseUrl + "/environment/create", params, this.options);
}

Spring

 @PostMapping("/environment/create")
public boolean createEnvironment(Environment environment, List<Client> clients, List<Account> accounts,
                                 List<Transaction> transactions,boolean isCloned) {
    environmentService.createEnvironment(environment,clients,accounts,transactions, isCloned);
    return true;
}

edit:

Well, even with Client[],etc.. I get

No primary or default constructor found for class [com.myproject.models.Client;

3
  • Do you have a no-arg constructor on Client? If not, try adding one to see if that helps Commented May 24, 2018 at 11:44
  • yes I have. The problem is with JSON Commented May 24, 2018 at 11:47
  • The exception you are getting typically deals with Java - either being the constructor is not proper or there is a modifier set incorrectly. I will have to follow this to see how it was resolved for my own curiosity. Commented May 24, 2018 at 11:53

1 Answer 1

2

You are missing the @RequestBody annotation before your method parameter that is meant to be deserialized from JSON. Given there is only one body in your request, you should wrap all of your objects in one DTO object. Also, dont pass your objects into an HttpParams object, but in your POST body.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.