WebService Rest

0

I'm wondering how do I send a post in the format json using form .

This is the form I use:

<form action="rest/carros"  enctype='application/json' accept-charset="utf-8" method="post">
  <input name='carro[descricacao]' value='carro de form'/>
  <input name='carro[nome]' value='citroen'/>
  <input name='carro[tipo]' value='4-portas'/>
  <input name='carro[urlFoto]' value='www.foto'/>
  <input name='carro[urlVideo]' value='www.video'/>
  <input type="submit" value='enviar'/>
</form>

This is the method that receives post :

@POST
@Consumes(MediaType.APPLICATION_JSON + "; charset=utf-8")
@Produces(MediaType.APPLICATION_JSON + "; charset=utf-8")
public String salvarCarro(Carro c){
        business.salvarCarro(c);
        return "salvo";
}

Everything is working normal, I already tested with postman and when I send an object like this:

{"carro":
        {
         "descricao":"um carro",
         "nome":"fiat",
         "tipo":"3-portas",
         "urlFoto":"www.foto",
         "urlVideo":"ww.video"
        }
}

It accepts perfectly, but when I do post using form it displays:

  

HTTP Status 415 - Unsupported Media Type

I do not know where I'm going wrong, or if I do not have jar to convert to a car object. I'm using jersey , just to remember.

    
asked by anonymous 16.01.2016 / 20:03

1 answer

0

Add @Consumes (MediaType.MULTIPART_FORM_DATA) so that the jersey knows that it can receive information in the form of a form. Have a look at this topic multiple-types-of -data-file-and-json

    
19.10.2016 / 20:36