Created
June 17, 2020 21:59
-
-
Save dennysfredericci/bcfa34ba64c95317d375f40defa8d2b1 to your computer and use it in GitHub Desktop.
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
@Converter | |
public class GenderConverter implements AttributeConverter<Gender, String> { | |
@Override | |
public String convertToDatabaseColumn(Gender gender) { | |
return gender.getCode(); | |
} | |
@Override | |
public Gender convertToEntityAttribute(String code) { | |
return Arrays.stream(Gender.values()).filter(gender -> gender.getCode().equals(code)) | |
.findFirst() | |
.orElse(Gender.NOT_AVAILABLE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment