First of all, please do not use Optional
as replacement for if-else statements. They were not intended for that purpose. Optional was intended to convey the possibility of null-values in public interfaces in code, instead of just documentation, and only that. Even using optional in a private method is against it's intention (you're supposed to know what your own code does).
Please read this answer from one of the architects behind the Optional class: Should Java 8 getters return optional type?
As an excercise, you should go through the source code for Optional and count how many throwaway objects you create for each name mapping operation.
As for your problem, this is the correct way to solve the immediate Sonar complaint:
public static String mapToName(Enum<?> customEnum) {
return customEnum == null ? "" : customEnum.name();
}
The question mark is a wildcard which denotes an unknown type.