2

I am trying to return custom error message by using @ExceptionHandler but I receive extra junk value of PK in the response. I have attached the screen shot as well as code here in for any suggestion.

Anyone can suggest here?

Java Code:

@ExceptionHandler(value = InvalidMediaPKException.class)
public ResponseEntity<MediaErrorWsDTO> handleInvalidMediaPKException(final InvalidMediaPKException exception)
{
    final MediaErrorWsDTO errors = new MediaErrorWsDTO();
    errors.setCode(HttpStatus.NOT_FOUND.toString());
    errors.setMessage(String.format(INVALID_MEDIA_ERROR_MSG));
    return new ResponseEntity<MediaErrorWsDTO>(errors, HttpStatus.NOT_FOUND);
}

enter image description here

Mr.A
  • 41
  • 4
  • What does MediaErrorWsDTO look like? – Essex Boy Dec 24 '21 at 10:55
  • @EssexBoy - I have taken two String attributes code and message. – Mr.A Dec 25 '21 at 11:46
  • `public class MediaErrorWsDTO implements Serializable { private static final long serialVersionUID = 1L; private String code; private String message; public MediaErrorWsDTO() { // default constructor } public void setCode(final String code) { this.code = code; } public String getCode() { return code; } public void setMessage(final String message) { this.message = message; } public String getMessage() { return message; } }` – Mr.A Dec 25 '21 at 11:59
  • It looks like a ZIP file header to me. :) – terrorrussia-keeps-killing Dec 25 '21 at 12:01

1 Answers1

0
@XmlRootElement
public class MediaErrorWsDTO implements Serializable
{
// some code
}

I got issue resolved after adding @XmlRootElement on MediaErrorWsDTO class.

sawan
  • 2,341
  • 3
  • 25
  • 51
Mr.A
  • 41
  • 4