Home > Software engineering >  getting a exception org.springframework.http.converter.HttpMessageNotWritableException
getting a exception org.springframework.http.converter.HttpMessageNotWritableException

Time:10-27

Check this link to see Image for details of the error on the browser

CodePudding user response:

Typically, this exception occurs when Spring fails to fetch the properties of a returned object. The most typical cause of this exception is usually that the returned object doesn't have any public getter methods for its properties. So, another common cause of our exception could be missing or using the wrong Jackson dependencies. In short, the general guideline for such an exception is to check for the presence of:

  • Default constructor
  • Getters
  • Jackson dependencies

Add this dependency to your pom.xml

    <dependency>
       <groupId>com.fasterxml.jackson.core</groupId>
       <artifactId>jackson-databind</artifactId>
       <version>2.5.0</version>
    </dependency>

you can see here

CodePudding user response:

This exception occurs when Spring fails to fetch the properties of a returned object. Another common cause of our exception could be missing or using the wrong Jackson dependencies. To prevent the exception define a getter method for each object's property we want to return in JSON. So add the getter methods in your Model class.

write @Data in your model class like this:-

@Data
public class Model {
}

it will automatically import all getters and setters

  • Related