@Override public void serialize(DataOutputStream dataOutputStream) throws IOException { dataOutputStream.writeInt(this.getId()); dataOutputStream.writeInt(this.getPatientId()); dataOutputStream.writeInt(this.getProgramId()); dataOutputStream.writeUTF(this.getName()); dataOutputStream.writeInt(this.getStatus()); dataOutputStream.writeUTF(this.getDateOfEnrollment()); dataOutputStream.writeUTF(this.getDateOfIncident()); dataOutputStream.writeInt(programStageInstances.size()); for (ProgramStage programStageInstance : programStageInstances) { programStageInstance.serialize(dataOutputStream); } }
@Override public void deSerialize(DataInputStream dataInputStream) throws IOException { this.setId(dataInputStream.readInt()); this.setPatientId(dataInputStream.readInt()); this.setProgramId(dataInputStream.readInt()); this.setName(dataInputStream.readUTF()); this.setStatus(dataInputStream.readInt()); this.setDateOfEnrollment(dataInputStream.readUTF()); this.setDateOfIncident(dataInputStream.readUTF()); // Read programstage instance int programStageInstanceSize = dataInputStream.readInt(); for (int i = 0; i < programStageInstanceSize; i++) { ProgramStage programStageInstance = new ProgramStage(); programStageInstance.deSerialize(dataInputStream); programStageInstances.add(programStageInstance); } }