Spring从3.2迁移到4.1.1:JSON序列化的麻烦 [英] Migration of Spring from 3.2 to 4.1.1: trouble with JSON serialization

查看:381
本文介绍了Spring从3.2迁移到4.1.1:JSON序列化的麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将项目从Spring 3迁移到Spring 4.1.1。我还将jackson从版本1迁移到版本2.3.0。

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.

提前致谢。

推荐答案

如果你想要使用void返回类型,您需要使用 @ResponseStatus(value = HttpStatus.OK)注释该方法

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, ...

详见如果Spring MVC控制器方法没有返回值,返回什么内容?

这篇关于Spring从3.2迁移到4.1.1:JSON序列化的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆