3
I have two classes: Contact and Operator. A in the Contact class I have a composition: private Operadora operadora
; I have a DAO where I have a class that returns a list of Contacts, in the console the list is displayed this way:
[Contato [nome=Diego Augusto, telefone=3525-4566, data=Mon Sep 14 13:43:42 BRT 2015, operadora=Operadora [nome=Tim, codigo=41, categoria=Celular, valor=2]]]
But when I try to pass this query to the method that serializes JSON the result is this:
{
nome: "Diego Augusto"
telefone: "3525-4566"
data: "2015-09-14T13:50:16-0300"
}
As you can see the carrier is not displayed, how can I view the carrier in JSON?
My controller:
@Controller
@Path("/contato")
public class ContatoController {
@Inject
private Result result;
@Inject
private ContatoDAO contatoDAO;
@Get
@Path("/contatos")
public void listAll() {
System.out.println("TESTE: "+contatoDAO.lista());
result.use(Results.json()).withoutRoot().from(contatoDAO.lista()).serialize();
}
}
DAO :
//Testando...
public List<Contato>lista(){
List<Contato>listaContatos = new ArrayList<>();
Contato c = new Contato();
Operadora o = new Operadora();
c.setNome("Diego Augusto");
c.setData(new Date());
c.setTelefone("3525-4566");
o.setCodigo(41);
o.setNome("Tim");
o.setCategoria("Celular");
o.setValor(new BigDecimal(2));
c.setOperadora(o);
listaContatos.add(c);
return listaContatos;
}
Your class
Contato
has a public getter for your reference toOperadora
?– Tulio F.
You do have @Túliof.
– DiegoAugusto
Try to clear your browser cache
Ctrl-F5
, sometimes you change the code but your browser is returning the page from the cache.– Tulio F.
Thank you for the answer, but I found the solution pro rs problem
– DiegoAugusto
So please answer your own question, it may help other people with the same problem. You can accept your own answer as correct.
– Tulio F.
Yes, I was already answering! Thank you.
– DiegoAugusto