0

I am developing a WEb Service Rest in java, netbeans.

This is the JSON I want to receive:

{
    "ticket":"2132158645161654561651616",
    "avaliacoes":[
        {
        "id":1,
        "nome":"Atendimento",
        "nota":5,
        "observacoes":"testeTEste"
        },
        {
        "id":2,
        "nome":"Atendimento",
        "nota":5,
        "observacoes":"testeTEste"
        }

    ]

}

Reception Class

    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    @Path("venda/enviardados")
    public String postVenda(@QueryParam("key") String key, @QueryParam("serial") String serial, VendaAvaliacao va) {

...
}

Entity Classes

public class VendaAvaliacao {

    private int id;
    private String ticket;
    //private List<VendaAvaliacaoInner> avaliacoes = new ArrayList<>();  //I've tried it too
    private VendaAvaliacaoInner[] teste;

}

public class VendaAvaliacaoInner {

    private int id;
    private String nome;
    private int nota;
    private String observacao;

}

The ticket is received and populated, but array = null.

I've read other similar topics but they did not help .... how can I do?

https://pt.stackoverflow.com/questions/6046/convers%C3%A3o-de-string-json-para-objeto-java?rq=1

https://pt.stackoverflow.com/questions/159725/receber-valor-de-array-json-para-string-java

https://pt.stackoverflow.com/questions/290759/como-obter-objetos-de-um-array-de-json-usando-jsonarray-no-java

1
  • Maybe the service REST you are consuming don't populate the data in the array. As an advice i would work with List<T> rather than T[] Commented Sep 5, 2019 at 13:10

1 Answer 1

1

Maybe the service REST you are consuming don't populate the data in the array.

As an advice i would work with List<T> rather than T[]

Also i see that you are mapping 3 properties in you object but the id property don't exist in raw JSON isn't it ?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.