Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Should I use Serializable for my DTO and why should I use?

As far as I know, Serializable should be used when deserialization is needed e.g. using dto as return object in APIs. But should I use Serializable for the whole DTO objects or just for the general one?

@Data
@AllArgsConstructor
public class GaDTO implements Serializable {

    private static final long serialVersionUID = -xxxx;

    private String id;
    private GaStatus gaStatus;
    private PlaTurn plaTurn;
    private PlaDTO pla1;
    private PlaDTO pla2;

}

This DTO is the return type of ResponseEntity but there are other DTOs that this GaDTO uses.

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PlaDTO implements Serializable {

    private static final long serialVersionUID = -yyyyyy;

    private List<PiDTO> pis;

    private PiDTO mainPi;

}

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PiDTO implements Serializable {

    private static final long serialVersionUID = -zzzzzz;

    private Integer stos;

}

Should I only use Serializable for GaDTO or do other DTOs need it too?
And why should I use it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You don’t need to implement Serializable and Deserializable for your DTO because it is already handled by Spring Boot Jackson Package.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading