Abdu Muhammadal
Abdu Muhammadal

Reputation: 143

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?

Upvotes: 3

Views: 5094

Answers (1)

user18770531
user18770531

Reputation:

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

Upvotes: 3

Related Questions