Skip to content

Instantly share code, notes, and snippets.

@dennysfredericci
Created June 17, 2020 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennysfredericci/ac67d7555d388d0501e083eba78f7e02 to your computer and use it in GitHub Desktop.
Save dennysfredericci/ac67d7555d388d0501e083eba78f7e02 to your computer and use it in GitHub Desktop.
@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