We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
询问有关本项目的使用和其他方面的相关问题。 springboot项目下如果使用fastjson2。比如用户的性别,数据库是0,1,加入返回前端需要的是男和女,可以通过什么办法,在不改变原有bean的情况下,通过注解把性别 序列化。文档上没有找到枚举转换的示例。
The text was updated successfully, but these errors were encountered:
可以用ValueFilter,比如
import com.alibaba.fastjson2.filter.ValueFilter; @Test public void test() { Bean bean = new Bean(); bean.type = Type.Big; ValueFilter valueFilter = (Object object, String name, Object value) -> { if (value instanceof Type) { switch ((Type) value) { case Big: return "大"; case Small: return "小"; default: break; } } return value; }; String json = JSON.toJSONString(bean, valueFilter); assertEquals("{\"type\":\"大\"}", json); } public enum Type { Big(101), Small(102); public final int code; Type(int code) { this.code = code; } } public static class Bean { public Type type; }
Sorry, something went wrong.
add testcase for issue #906
e6e8fe6
No branches or pull requests
请描述您的问题
询问有关本项目的使用和其他方面的相关问题。
springboot项目下如果使用fastjson2。比如用户的性别,数据库是0,1,加入返回前端需要的是男和女,可以通过什么办法,在不改变原有bean的情况下,通过注解把性别 序列化。文档上没有找到枚举转换的示例。
The text was updated successfully, but these errors were encountered: