Android sending POST Json using JAX-RS receiving object with null array

Asked

Viewed 243 times

1

I am trying to post an object but the array only comes null.. someone can tell me what is wrong?

@XmlRootElement
public class Produto implements Serializable{

    private String nome;
    get e set...

    private List<Tipo> tipos;
    get e set...

}

@XmlRootElement
public class Tipo implements Serializable{

    private String nome;
    get e set...

}

this is the method with your notes

@POST
@Path("/cadastrar")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response addProduto(Produto produto)

follows the json format I’m sending

{
"nome":"Teste produto",
"tipos":[{"nome":"Teste 1"},{"nome":"Teste 2"},{"nome":"Teste 3"}]
}

the problem is that arrives the product only with the name, the List is coming null, someone has idea of what is?!

  • 1

    First thing: test WS using any customer to make sure that the returned JSON is actually the same as this one. If you don’t have one, there’s an extension for Chrome called Postman that does the job well. Second, if everything is set on the server, post the code that calls WS and receives the empty object.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.