Tuesday, July 22, 2014

Re: Deserialization error when adding a ArrayList to a DTO


I just did some more digging around. I have two DTOs. One is the ContaienrDto posted above. Another one is a DeviceDto. When i add the ArrayList<String> to that, it works. How can that be?

Thanks!

The DeviceDto looks like this:
}

    public DeviceDto(Integer id, long imei, Timestamp lastSync, String macAddress, int status, String deviceCertificate, String firmware, HardwareDTO hardware,
            Set<ContainerDto> containers) {
        super();
        this.id = id;
        this.imei = imei;
        this.lastSync = lastSync;
        this.macAddress = macAddress;
        this.status = status;
        this.deviceCertificate = deviceCertificate;
        this.firmware = firmware;
        this.hardware = hardware;
        this.containers = containers;
    }

    /*
     * Getters & setters (generated)
     */
    public ArrayList<String> getGroupList() {
return groupList;
}

public void setGroupList(ArrayList<String> groupList) {
this.groupList = groupList;
}
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public long getImei() {
        return imei;
    }

    public void setImei(long imei) {
        this.imei = imei;
    }

    public Timestamp getLastSync() {
        return lastSync;
    }

    public void setLastSync(Timestamp lastSync) {
        this.lastSync = lastSync;
    }

    public String getMacAddress() {
        return macAddress;
    }

    public void setMacAddress(String macAddress) {
        this.macAddress = macAddress;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getDeviceCertificate() {
        return deviceCertificate;
    }

    public void setDeviceCertificate(String deviceCertificate) {
        this.deviceCertificate = deviceCertificate;
    }

    public String getFirmware() {
        return firmware;
    }

    public void setFirmware(String firmware) {
        this.firmware = firmware;
    }

    public HardwareDTO getHardware() {
        return hardware;
    }

    public void setHardware(HardwareDTO hardware) {
        this.hardware = hardware;
    }

    public Set<ContainerDto> getContainers() {
        return containers;
    }

    public void setContainers(Set<ContainerDto> containers) {
        this.containers = containers;
    }

    /*
     * Getters and Setters to make it back compatible // TODO review those
     * methods if Driver is used
     */

    public String getStId() {
        return new Integer(this.getId()).toString();
    }

    public String getStImei() {
        return new Long(this.getImei()).toString();
    }

    public void setStImei(String stImei) {
        this.setImei(new Long(stImei).longValue());
    }

    public String getType() {
        return this.getHardware().getManufacturer() + " " + this.getHardware().getModel();
    }

    public String getFirmwareVersion() {
        return this.getFirmware();
    }

    public void setFirmwareVersion(String firmware) {
        this.setFirmware(firmware);
    }

    public String getStStatus() {
        String status = "N/A";
        if (this.getStatus() == 0) {
            status = "Inactive";
        } else if (this.getStatus() == 1) {
            status = "Active";
        }
        return status;
    }

    public void setStStatus(String stStatus) {
        if (stStatus.equals("Inactive")) {
            this.setStatus(0);
        } else if (stStatus.equals("Active")) {
            this.setStatus(1);
        }
    }

    public String getStLastSync() {
        // return String.format("%1$TD %1$TT", this.getLastSync());
        // return (new
        // SimpleDateFormat("dd.MM.yyyy H:m").format(this.getLastSync()).toString());
        return this.getLastSync().toString(); // FIXME set a format
    }

    /*
     * Other methods (generated)
     */
    // containers not included. It would bring to an infinite loop
    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("DeviceDto [id=").append(id).append(", imei=").append(imei).append(", lastSync=").append(lastSync).append(", macAddress=")
                .append(macAddress).append(", status=").append(status).append(", deviceCertificate=").append(deviceCertificate).append(", firmware=")
                .append(firmware).append(", hardware=").append(hardware).append("]");
        return builder.toString();
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((containers == null) ? 0 : containers.hashCode());
        result = prime * result + ((deviceCertificate == null) ? 0 : deviceCertificate.hashCode());
        result = prime * result + ((firmware == null) ? 0 : firmware.hashCode());
        result = prime * result + ((hardware == null) ? 0 : hardware.hashCode());
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result + (int) (imei ^ (imei >>> 32));
        result = prime * result + ((lastSync == null) ? 0 : lastSync.hashCode());
        result = prime * result + ((macAddress == null) ? 0 : macAddress.hashCode());
        result = prime * result + status;
        return result;
    }

    // containers not compared. It would bring to an infinite loop
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        DeviceDto other = (DeviceDto) obj;
        if (deviceCertificate == null) {
            if (other.deviceCertificate != null) {
                return false;
            }
        } else if (!deviceCertificate.equals(other.deviceCertificate)) {
            return false;
        }
        if (firmware == null) {
            if (other.firmware != null) {
                return false;
            }
        } else if (!firmware.equals(other.firmware)) {
            return false;
        }
        if (hardware == null) {
            if (other.hardware != null) {
                return false;
            }
        } else if (!hardware.equals(other.hardware)) {
            return false;
        }
        if (id == null) {
            if (other.id != null) {
                return false;
            }
        } else if (!id.equals(other.id)) {
            return false;
        }
        if (imei != other.imei) {
            return false;
        }
        if (lastSync == null) {
            if (other.lastSync != null) {
                return false;
            }
        } else if (!lastSync.equals(other.lastSync)) {
            return false;
        }
        if (macAddress == null) {
            if (other.macAddress != null) {
                return false;
            }
        } else if (!macAddress.equals(other.macAddress)) {
            return false;
        }
        if (status != other.status) {
            return false;
        }
        return true;
    }

}


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment