Category Archives: JsonMappingException

Required request body content is missing: org.springframework.web.method.HandlerMethod


You can’t send a request body with an HTTP GET request. You should modify your call so that it only supports POST, and POST your JSON to that endpoint.

If you want to GET information about a bean, you should create a separate controller method that does that (and does not require a request body).

Also, double-check your endpoint definitions  in the $.ajax call.

70 total views, no views today

exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.json.JSONObject

Could not write content: No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) )


controller methods return simple POJOs – Collection<Bookmark>, and Bookmark, etc., 

When an HTTP request comes in that specifies an Accept header, Spring MVC loops through the configured HttpMessageConverter until it finds one that can convert from the POJO domain model types into the content-type specified in the Accept header, if so configured.

Spring Boot automatically wires up an HttpMessageConverter that can convert generic Object’s to JSON, absent any more specific converter. HttpMessageConverter s work in both directions: incoming requests bodies are converted to Java objects, and Java objects are converted into HTTP response bodies.

To solve Exception just override the default behaivour of the HttpMessageConverter provided by spring.




    @Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
jsonConverter.setObjectMapper(objectMapper);
return jsonConverter;
}


This will do the trick for you.

72 total views, no views today