[英]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 eg using dto as return object in APIs.据我所知,当需要反序列化时应该使用 Serializable,例如在 API 中使用 dto 作为返回 object。 But should I use Serializable for the whole DTO objects or just for the general one?
但是我应该对整个 DTO 对象使用 Serializable 还是只对一般对象使用 Serializable?
@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.此 DTO 是
ResponseEntity
的返回类型,但此 GaDTO 使用其他 DTO。
@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?我应该只对 GaDTO 使用 Serializable 还是其他 DTO 也需要它? And why should I use it?
我为什么要使用它?
You don't need to implement Serializable and Deserializable for your DTO because it is already handled by Spring Boot Jackson Package.你不需要为你的 DTO 实现 Serializable 和 Deserializable,因为它已经被 Spring Boot Jackson Package 处理了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.