0

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();
    }

}
m_br0_89
  • 85
  • 2
  • 8
  • 1
    Possible duplicate of [POST JSON fails with 415 Unsupported media type, Spring 3 mvc](http://stackoverflow.com/questions/11492325/post-json-fails-with-415-unsupported-media-type-spring-3-mvc) – Naros Aug 06 '16 at 10:37
  • Refer this http://stackoverflow.com/questions/4110664/gson-directly-convert-string-to-jsonobject-no-pojo – JRA Mar 22 '17 at 05:23

0 Answers0