0
    public enum Metadata{
        AC, CD;
@jsonCreator
public static Metadata get(String value) throw customException
if(!isValid(value)){
throw customException();
}
    }

My handler method

@ExceptionHandler(customException.class)
public ResponseEntity<Response> handeljsonError(customException e){
return response;
}

when custom exception is thrown from Enum metadata so flow is not coming on custom handler instead of that it is going to httpMessageNonReadableException which is other override method so when I debug its cause its shows ValueInstantiationException.

I want my custom exception method should get run instead of httpMessageNonReadableException

1 Answers1

0

The class should extend the ResponseEntityExceptionHandler with @ControllerAdvice annotation.

@ControllerAdvice
public class ControllerAdvisor extends ResponseEntityExceptionHandler 

ResponseEntityExceptionHandler is called by spring only in HTTP flow, make sure your code is in the scope of HTTP.

Arpit Asati
  • 130
  • 2
  • 16