1
I am creating a product register, and when I pass through Postman the JSON of my product to be recorded, its type is being saved as NULL.
The product types are an Enum, I will put down the code I tried to use to record the guys. Am I doing something wrong? Should I pass JSON differently? I appreciate the help
Enum code :
public enum TipoProduto {
INFORMATICA(1, "informatica"), ELETRONICOS(2, "eletronicos"), CAMA(3, "cama"), MESA(4, "mesa"), BANHO(5, "banho"), CALCADOS(6, "calcados");
private String descricao;
private Integer codigo;
private TipoProduto(Integer codigo, String descricao) {
this.codigo = codigo;
this.descricao = descricao;
}
public String getDescricao() {
return descricao;
}
public Integer getCodigo() {
return codigo;
}
}
How I am trying to pass JSON on POSTMAN:
{
"nome": "Notebook",
"TipoProduto": 1,
"valor": 1300.00,
"cor": "Cinza Fosco",
"especificacoes": "8GB RAM, i7, 256GB"
}
How is JSON parsed? How the object is persisted in the database?
– Leonardo Lima
So, to persist I simply call Entity manager and give a persist on the product. In Product Resource I do the following: @POST @Produces(Mediatype.APPLICATION_JSON) public Response adds(Product) { productDao.adds(product); URI Uri = URI.create("/product/" + product.getId()); Return Response.created(Uri). build(); }
– Bussola
Have you debugged the program in Resource before persisting? Enum is filled in correctly?
– Leonardo Lima
So I debug it now, and it’s being filled as null :/
– Bussola
put the mapping of the entity that has the Enum Typoproduct
– André