class org.springframework.http.converter.HttpMessageNotWritableException No converter for [class java.lang.Boolean] with preset Content-Type 'null'

Viewed 23

class org.springframework.http.converter.HttpMessageNotWritableException No converter for [class java.lang.Boolean] with preset Content-Type 'null'

My Controller has a method that returns a Boolean type. Since there are some client services that require it to return the response as a "text/plain".

@RequestMapping(value="/test",method=RequestMethod.POST,produces= "text/plain")
public Boolean test() {
 return <boolean value>
}

When I use this it throws the below error class org.springframework.http.converter.HttpMessageNotWritableException No converter for [class java.lang.Boolean] with preset Content-Type 'null'

1 Answers

While hitting the request try adding the Accept header in curl or Postman!

(Since you're returning a Boolean, use toString() to convert boolean to string before returning response)

Accept: text/plain

Related