S
S
Skoleev2021-08-15 13:27:23
Java
Skoleev, 2021-08-15 13:27:23

Different DTOs for creating/getting objects VS one DTO but forbid null serialization?

I'm just learning, making the first programs, and I get several DTO classes for creating and receiving objects (obviously less information is needed to create).
I thought that we could do it a little differently:
One DTO, create a separate constructor for creating objects in it. Unique fields that are only used on creation are not initialized on getting the object. And in the serialization settings, disable the serialization of null objects. But would this be good practice? Or will it be a shameful crutch, which will be ashamed to send to someone?

I really appreciate your answers! Also I ask a question only because it is weak in good/bad practices

PS whether transfer of object with some superfluous null fields affects optimization?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2021-08-15
@Skoleev

Good afternoon.
As for me, it's better to create a separate DTO for each need, instead of composing everything into one.
For example, UserCreationDTO, UserRequestDTO, UserResponseDTO, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question