I have the following JSON:
[{"estado":true,"cod":0,"id":"1237273960","dispositivo":"123456789012345","ELEMENTO":"AU","nom_ATRIBUTO":"ARBPL","val_ATRIBUTO":"DCF9D2_1","fecha":1585519200000,"descargado":"N"},{"estado":true,"cod":1,"id":"1237273961","dispositivo":"123456789012345","tip_ELEMENTO":"OT","nom_ATRIBUTO":"ARBPL","val_ATRIBUTO":"DCF9D2_1","fecha":1585519200000,"descargado":"N"}]
And the GOT class that is equivalent to the objects that make up the JSON
public class GOT {
private Integer cod;
private String id;
private String dispositivo;
private String ELEMENTO;
private String nom_ATRIBUTO;
private String val_ATRIBUTO;
private Date fecha;
private String descargado;
private boolean estado = true;
public boolean isEstado() {
return estado;
}
public void setEstado(boolean estado) {
this.estado = estado;
}
public Integer getCOD() {
return cod;
}
public void setCOD(Integer cOD) {
cod = cOD;
}
public String getID() {
return id;
}
public void setID(String iD) {
id = iD;
}
public String getDISPOSITIVO() {
return dispositivo;
}
public void setDISPOSITIVO(String dISPOSITIVO) {
dispositivo = dISPOSITIVO;
}
public String getELEMENTO() {
return ELEMENTO;
}
public void setELEMENTO(String eLEMENTO) {
ELEMENTO = eLEMENTO;
}
public String getNOM_ATRIBUTO() {
return nom_ATRIBUTO;
}
public void setNOM_ATRIBUTO(String nOM_ATRIBUTO) {
nom_ATRIBUTO = nOM_ATRIBUTO;
}
public String getVAL_ATRIBUTO() {
return val_ATRIBUTO;
}
public void setVAL_ATRIBUTO(String vAL_ATRIBUTO) {
val_ATRIBUTO = vAL_ATRIBUTO;
}
public String getDESCARGADO() {
return descargado;
}
public void setDESCARGADO(String dESCARGADO) {
descargado = dESCARGADO;
}
public Date getFECHA() {
return fecha;
}
public void setFECHA(Date fECHA) {
fecha = fECHA;
}
}
To work with that JSON, I have created the import class that is equivalent to JSON, or so I understand since I don't have much experience with this technology.
public class Impor {
GOT[] datos;
public GOT[] getDatos() {
return datos;
}
public void setDatos(GOT[] datos) {
this.datos = datos;
}
}
For the mapping of the JSON I use Jackson.
InputStream datos = request.getInputStream();
Impor datosAlmacenar = new ObjectMapper().readValue(datos, Impor.class);
But I am getting the following error trace and I don't understand the reason.
Cannot deserialize instance of `com.paquete.ajax.model.Impor` out of START_ARRAY token at [Source: (org.apache.catalina.connector.CoyoteInputStream); line: 1, column: 1]
The error is in the Import class but I don't see where since, as far as I can tell, that class is equivalent to JSON.
Any help is welcome, since I've been thinking about this problem all day today and I don't see the solution
I think that in order to make the mapper as you are trying to do, the JSON must have a structure similar to
Where corresponds to the name of the class
datos
variableGOT[] datos;
Import