You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@JsonCreatorpublicstaticTeamTypefrom(Stringvalue) {
for (TeamTypestatus : TeamType.values()) {
if (status.getValue().equals(value)) {
returnstatus;
}
}
returnnull;
}
@JsonValuepublicStringgetValue() {
returnvalue;
추가로 Enum 클래스를 작성하실 때 위와 같이 @JsonCreator와 @JsonValue로 역직렬화를 구현해놓으셔야 Enum Value로 Enum 타입의 변수에 대입이 가능해집니다. @JsonCreator가 존재하지 않으면 DTO로 넘어온 Enum Value로는 Enum 타입의 변수에 대입이 불가능해 타입 에러가 발생합니다.
The text was updated successfully, but these errors were encountered:
DTO에 Enum Field들을 편하게 Validation 하기 위해 커스텀 어노테이션을 작성해두었습니다.
위와 같이 DTO의 필드에 @ValidEnum을 붙여주시면 되고 enumClass로 Enum 클래스를 주시면 됩니다.
ConstraintValidator를 상속한 EnumValidator의 isValid에서 Enum value가 유효한지 확인합니다.
추가로 Enum 클래스를 작성하실 때 위와 같이 @JsonCreator와 @JsonValue로 역직렬화를 구현해놓으셔야 Enum Value로 Enum 타입의 변수에 대입이 가능해집니다. @JsonCreator가 존재하지 않으면 DTO로 넘어온 Enum Value로는 Enum 타입의 변수에 대입이 불가능해 타입 에러가 발생합니다.
The text was updated successfully, but these errors were encountered: