-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
기존에 Integer로 저장하던 age를 Age enum으로 저장할 수 있게 함. Age, Gender enum의 value를 name(한글)과 매핑하였음. 직렬화, 역직렬화 시에 value->name, name->value로 자동으로 변환될 수 있게 함.
- Loading branch information
1 parent
d2f0876
commit edbdb2a
Showing
7 changed files
with
93 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package likelion.MZConnent.domain.member; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public enum Age { | ||
FOURTH_GRADE("4학년"), | ||
FIFTH_GRADE("5학년"), | ||
SIXTH_GRADE("6학년 이상"); | ||
|
||
private final String name; | ||
|
||
@JsonValue | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@JsonCreator | ||
public static Age fromName(String name) { | ||
for (Age age : Age.values()) { | ||
if (age.getName().equals(name)) { | ||
return age; | ||
} | ||
} | ||
log.info("존재하지 않는 enum type(Age): {}", name); | ||
throw new IllegalArgumentException(name +"은 존재하지 않는 enum type입니다.(Age)"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,32 @@ | ||
package likelion.MZConnent.domain.member; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public enum Gender { | ||
MALE, FEMALE | ||
MALE("남성"), | ||
FEMALE("여성"); | ||
|
||
private final String name; | ||
|
||
@JsonValue | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@JsonCreator | ||
public static Gender fromName(String name) { | ||
for (Gender gender : Gender.values()) { | ||
if (gender.getName().equals(name)) { | ||
return gender; | ||
} | ||
} | ||
log.info("존재하지 않는 enum type(Gender): {}", name); | ||
throw new IllegalArgumentException(name +"은 존재하지 않는 enum type입니다.(Gender)"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters