'Spring boot Postmapping not working for request body with List

I am trying to send array list JSON as request body in spring boot project but it gives me error. It it working fine if i just use json object.

I need to send request something like below.

[
    {
        "name":"abc"
.....
    }
]

Controller:

@PostMapping("/addr")
public List<String> getAddr(@RequestBody List<Address> addr)

Address.java

@Data
@Builder
@AllArgsConstructor
@NoArgConstructor
public class Address {
private String name;
....
}

when i hit this API it gives me following error Error:

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

Please suggest how to fix?



Solution 1:[1]

This message implies that you are trying to use a default constructor for java.util.List.

Something like

new List();

If that's the case, try using ArrayList for example, because List is the interface, so you can only instanciate the implementation classes of List.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pedro Luiz