Sobes.tech
Junior — Middle

Which annotation is used to exclude a DTO field from automatic object mapping?

sobes.tech AI

Answer from AI

To exclude a DTO field from automatic object mapping, the @Transient annotation is often used.

This annotation indicates that the field should not participate in serialization or mapping, for example, when working with JSON or ORM.

Example:

public class UserDTO {
    private String name;

    @Transient
    private String temporaryData; // this field will not be considered in mapping

    // getters and setters
}

If using a library like Jackson, the @JsonIgnore annotation can be used to exclude a field from serialization.