Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@Converter(autoApply = true)
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.UNKNOWN);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment