У меня есть веб-сервис, сконструированный так
@RestController
public class GreetingController {
@PostMapping(path = "/greetingws")
public Foo greeting(@RequestBody Foo dto) {
return dto;
}
}
Когда я использую веб-сервис, я делаю так
Foo f = new Foo("kkkkk");
ResponseEntity<String> t2 = restTemplate
.exchange("http://localhost:8080/greetingws", HttpMethod.POST, new HttpEntity<Foo>(f), String.class);
Но он возвращает ошибку:
org.springframework.web.client.HttpClientErrorException$BadRequest: 400 : [{"timestamp":"2020-04-24T13:03:30.191+0000","status":400,"error":"Bad Request","message":"JSON parse error: Cannot construct instance of it.test.demo.controller.Foo (although at least one C... (7991 bytes)]
Мой Foo
класс, как показано ниже:
public class Foo {
private String nome;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public Foo(String nome) {
super();
this.nome = nome;
}
@Override
public String toString() {
return "Foo [nome=" + nome + "]";
}
}
Где я делаю ошибку?