I try send json to controller, but I can't get that on controller. Server responce with 415 status. What I am doing wrong? I tried different Types on controller, but it still 415 status. Spring 4, Spring Boot use My json:
var res = {'test' : "tt" , 'right' : '22'}
$.post('/test/${doc.id}',res,'application/json')
And my Controller:
@RequestMapping(value = "/test/{id}", method = RequestMethod.POST ,consumes = "application/json")
public void test(@RequestBody Foo allRequestParam){
System.out.println(allRequestParam);
}
My Foo:
public class Foo implements Serializable {
private static final long serialVersionUID = -5054749928374932861L;
private String test;
private String right;
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
public String getRight() {
return right;
}
public void setRight(String right) {
this.right = right;
}
public Foo() {
}
public Foo(String test, String right) {
this.test = test;
this.right = right;
}
}
I included jackson to my pom.xml and my AppConfig:
@EnableAsync
@Configuration
@ComponentScan("base")
@EnableTransactionManagement
@EnableWebMvc
@EnableJpaRepositories({"base.contracts.repository", "base.edocs.repository"})
public class AppConfig extends WebMvcConfigurerAdapter {
private static final Logger logger = Logger.getLogger(AppConfig.class);
/*...some config......*/
@Bean
public MappingJackson2HttpMessageConverter jsonConverter(){
return new MappingJackson2HttpMessageConverter();
}
}