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
package com.test.fastjson2; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.annotation.JSONCreator; import com.alibaba.fastjson2.annotation.JSONType; import lombok.Getter; import java.util.Optional; @JSONType(writeEnumAsJavaBean = true) @Getter public enum ServiceCode { /** * SUCCESS */ SUCCESS("00", "SUCCESS"), /** * SERVER_ERROR */ SERVER_ERROR("01", "ERROR"); ServiceCode(String code, String msgId) { this.code = code; this.msgId = msgId; } private String code; private String msgId; private String msg; public void setMsg(String msg){ this.msg=msg; } @JSONCreator public static ServiceCode valueOf( String code, String msg) { ServiceCode status; switch (code) { case "0000": status = ServiceCode.SUCCESS; break; default: status = ServiceCode.SERVER_ERROR; break; } Optional.ofNullable(msg).ifPresent(msgVal -> status.setMsg(msgVal)); return status; } public static void main(String[] args) { ServiceCode statusCode= ServiceCode.SERVER_ERROR; statusCode.setMsg("1111"); String s = JSON.toJSONString(statusCode); ServiceCode statusCode1 = JSON.parseObject(s, ServiceCode.class); System.out.println(s); System.out.println(statusCode1); }
The text was updated successfully, but these errors were encountered:
enum使用(writeEnumAsJavaBean = true序列化成为java bean之后,怎么使用jsoncreator的方式反序列化成功?目前使用自定义反序列化类是可以的,但是jsoncreator的方式失败。
Sorry, something went wrong.
bug fix for enum JSONCreator support, fix issue #829
7c02d58
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.16-SNAPSHOT/ 问题已经修复,请用2.0.16-SNAPSHOT帮忙验证,2.0.16版本预计在10月30日前发布
https://github.com/alibaba/fastjson2/releases/tag/2.0.16 问题已修复,请用2.0.16版本
No branches or pull requests
The text was updated successfully, but these errors were encountered: