1
Guys, I’m having this error when converting the object to json. I’m using gson. I have tried to send the whole object and had the same error, changed and separated the object to try to locate where the problem is, but without success.
Gson gson = new Gson();
HashMap<String, String> params = new HashMap<>();
params.put("cliente",gson.toJson(vend.getCliente()));
params.put("empresa",gson.toJson(vend.getEmpresa()));
params.put("endereco",gson.toJson(vend.getEndereco()));
params.put("carrinho",gson.toJson(vend.getCarrinho()));
params.put("formPagamento",gson.toJson(vend.getFormPagamento()));
params.put("troco",gson.toJson(vend.getTrocoParaVenda()));
params.put("data",gson.toJson(vend.getDataVenda()));
params.put("valor",gson.toJson(vend.getVlrTotalVenda()));
I get this mistake:
java.lang.StackOverflowError
at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:147)
at java.lang.StringBuffer.append(StringBuffer.java:219)
at java.io.StringWriter.write(StringWriter.java:147)
at com.google.gson.stream.JsonWriter.string(JsonWriter.java:551)
at com.google.gson.stream.JsonWriter.writeDeferredName(JsonWriter.java:402)
at com.google.gson.stream.JsonWriter.value(JsonWriter.java:465)
at com.google.gson.internal.bind.TypeAdapters$3.write(TypeAdapters.java:169)
at com.google.gson.internal.bind.TypeAdapters$3.write(TypeAdapters.java:151)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:112)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:239)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:97)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:61)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:112)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:239)
at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:968)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:97)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:61)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:112)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:239)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:112)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:239)
at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:968)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:97)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:61)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:112)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:239)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:112)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:239)
at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:968)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:97)
at com.google
If possible I prefer to send the whole object through the webservice. Note: I’m using Volley.
Sales class:
public class Venda {
private Long idVenda;
private Date dataVenda;
private String statusVenda;
private Double vlrTotalVenda;
private Pessoa empresa;
private Pessoa cliente;
private Double trocoParaVenda;
private Endereco endereco;
private Boolean retirada;
private List<ItemVenda> carrinho;
private String formPagamento;
Itemvenda class
public class ItemVenda {
private Long idItemVenda;
private Integer quantItemVenda;
private Produto produtoItemVenda;
private Double vlrItemVenda;
@Expose(serialize = false, deserialize = false)
private Venda vendaItemVenda;
private List<Ingrediente> ingredientesProduto;
private List<Ingrediente> ingredientesAdicionais;
Classe Pessoa:
public class Pessoa {
private Long idPessoa;
private String nomeFantasiaPessoa;
private String imagem;
private String razaoSocialPessoa;
private String senhaPessoa;
private String telefonePessoa;
private String celularPessoa;
private String emailPessoa;
private String statusPessoa;
private String tipoPessoa;
private String cpfCnpjPessoa;
private String rgIePessoa;
private List<Endereco> enderecos;
private String categoriaPessoa;
private String tempoPreparo;
private Double valorEntrega;
private List<Categoria> categorias;
Address Class
public class Endereco {
private Long idEndereco;
private String estadoEndereco;
private String cidadeEndereco;
private String bairroEndereco;
private String ruaEndereco;
private String numeroEndereco;
private String complementoEndereco;
private String cepEndereco;
private Long pessoa;
What is the definition of the class
ItemVenda
? If she has a reference to the classVenda
, you will have this problem.– carlosfigueira