Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自定义返回值解码 #198

Open
wangxiaoyan369 opened this issue Apr 11, 2024 · 5 comments
Open

自定义返回值解码 #198

wangxiaoyan369 opened this issue Apr 11, 2024 · 5 comments

Comments

@wangxiaoyan369
Copy link

在业务中返回json一般都是一种统一的格式,比如

{
    "code": 1000,
    "data": {
        "name": "a",
        "age": 18
    }
}

有一个方法

@Get("/getUser")
User getUser();

我只需要data里的数据,可以自定义的去解析json字符串,并取data节点内的数据序列化成User对象并返回吗?

@wangxiaoyan369
Copy link
Author

看了下拦截器和自定义注解声明周期,都必须指定方法返回参数的泛型,这也就意味只能服务一种返回值的情况,有可以适配所有方法的拦截器吗,原泛型参数可以按字节码对象的形式传递给自定义的处理方法

@ViCrack
Copy link

ViCrack commented Apr 30, 2024

同问,而且接口级别的BodyType只有编码可以配置,而解码没有地方配置

@wangxiaoyan369
Copy link
Author

同问,而且接口级别的BodyType只有编码可以配置,而解码没有地方配置

可以去gitee仓库,在那里我得到答案了

@ViCrack
Copy link

ViCrack commented Apr 30, 2024

没找到答案,不过我目前可以用全局转换器临时改了改

@jinceon
Copy link

jinceon commented Aug 6, 2024

https://gitee.com/dromara/forest/issues/I9G1IK

gitee issue的回复里的链接已经打不开了。
官方文档里有个自定义转换器,感觉比拦截器更合适
https://forest.dtflyx.com/pages/1.5.36/custom_converter/#%E5%AE%9E%E7%8E%B0-forestconverter-%E6%8E%A5%E5%8F%A3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants