0

In a mapper interface , I have created a default method to map a string to an enum using a bunch of switch/case.

@Mapper(unmappedTargetPolicy = ReportingPolicy.WARN, componentModel="spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface ContractMapper {

Logger LOGGER = LogManager.getLogger(ContractMapper.class);

all the mappingstuff...

@Named("getEnum")
default statusEnum getStatusEnum(String status){

    if (status == null){
        return statusEnum.NoStatus;
    } else {

        switch (status) {
        case ...

        default:
            LOGGER.warn("unknown  status {}", status);
            return statusEnum.NoStatus;


        }
    }

I need a logger for when the mapping fail, is there a way to have one without sonar yelling at me because it is not private?

0c7
  • 3
  • 5

1 Answers1

2

You can always suppress the particular sonar rule for your mapper. If you can't do that then you could use an abstract class instead of an interface.

e.g.

@Mapper(unmappedTargetPolicy = ReportingPolicy.WARN, componentModel="spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public abstract class ContractMapper {

    protected static final Logger LOGGER = LogManager.getLogger(ContractMapper.class);

//...
}
Filip
  • 19,269
  • 7
  • 51
  • 60