alibaba / fastjson

FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
https://github.com/alibaba/fastjson2/wiki/fastjson_1_upgrade_cn
Apache License 2.0
25.76k stars 6.5k forks source link

spring mvc问题 #981

Open shuohao opened 7 years ago

shuohao commented 7 years ago

qq 20170104185948 以上代码在用Jackson的时候能正确返回json,但是用fastjson之后是返回经过转义的字符串 "{\"msg\":\"ok\",\"code\":200}" 难道这种简单的自定义的也需要创建model来转吗。。

CharkeyQK commented 7 years ago

不需要再创建 model

[org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor] - Written [{
    "code": 200,
    "msg": "OK"
}] as "application/json;charset=UTF-8" using [org.springframework.http.converter.StringHttpMessageConverter@22d55bca]

这是我这边测试的情况,你看看你那边相关的配置,比如 message-converters 的配置

shuohao commented 7 years ago

@CharkeyQK
qq 20170105110723 这么配就可以 了 之前少配了StringHttpMessageConverter,我以为spring默认初始化6个Converter不需要配呢,跟了代码发现如果只配FastJsonHttpMessageConverter4话,所有的解析都由fastjson来转换