I recently migrate our project from Spring 3 to Spring 4.1.1. I also migrate jackson from version 1 to version 2.3.0.
Now, I encounter problems when using controllers with void response
@RequestMapping(value="toto", method="POST")
public @ResponseBody void myController() {
//content
}
In runtime, when calling it I get an exception of this form:
Failed to evaluate serialization for type [void]: java.lang.IllegalStateException: Failed to instantiate standard serializer (of type com.fasterxml.jackson.databind.ser.std.NullSerializer): Class com.fasterxml.jackson.databind.ser.BasicSerializerFactory can not access a member of class com.fasterxml.jackson.databind.ser.std.NullSerializer with modifiers "private"
I wonder if someone encountered the same kind of issue or have an idea of what is wrong.
Thanks in advance.
If you want to use a void return type you need to annotate the method with @ResponseStatus(value = HttpStatus.OK)
:
@RequestMapping(value = "/usage")
@ResponseStatus(value = HttpStatus.OK)
public void doSomething(HttpServletRequest request, ...
For details see What to return if Spring MVC controller method doesn't return value?
Your method is not returning anything, when Spring is waiting for a return value to serialize using HttpMessageConverters. You should rather have something like this:
@RequestMapping(value="toto", method="POST")
@ResponseBody
public FooBar myController() {
//
return fooBar;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With