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
toJSONString
fastjson 和 fastjson2 对Enum使用toJSONString 不一致
请填写以下信息:
import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONWriter; import com.alibaba.fastjson2.annotation.JSONField; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class Issue972Mutated_141 { public enum Type { @JSONField(name = "Rejected") REJECTED, @JSONField(name = "Pending") PENDING, } public static class Bean { public Type type; } public enum Type1 { @com.alibaba.fastjson.annotation.JSONField(name = "Rejected") REJECTED, @com.alibaba.fastjson.annotation.JSONField(name = "Pending") PENDING, } public static class Bean1 { public Type1 type; } @Test public void testMutated() { String str = JSON.toJSONString(Type.REJECTED); assertEquals("\"Rejected\"", str); } @Test public void testMutatedfj() { String str = com.alibaba.fastjson.JSON.toJSONString(Type1.REJECTED); assertEquals("\"Rejected\"", str); } @Test public void testMutated0() { Bean bean = new Bean(); bean.type = Type.REJECTED; String str = JSON.toJSONString(bean, JSONWriter.Feature.WriteEnumsUsingName); assertEquals("{\"type\":\"Rejected\"}", str); } @Test public void testMutated0fj() { Bean1 bean1 = new Bean1(); bean1.type = Type1.REJECTED; String str = com.alibaba.fastjson.JSON.toJSONString(bean1, SerializerFeature.WriteEnumUsingName); assertEquals("{\"type\":\"Rejected\"}", str); } }
两者结果不一致
result: org.opentest4j.AssertionFailedError: Expected :"Rejected" Actual :"REJECTED"
The text was updated successfully, but these errors were encountered:
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson/2.0.50-SNAPSHOT/ 问题已修复,请帮忙用2.0.50-SNAPSHOT版本验证,2.0.50版本预计在5月12日前发布
Sorry, something went wrong.
enum support fastjson 1.x JSONField#name, for issue #2521
89a6c29
经验证已修复,辛苦wenshao
https://github.com/alibaba/fastjson2/releases/tag/2.0.50 2.0.50已发布,请用新版本
No branches or pull requests
问题描述
fastjson 和 fastjson2 对Enum使用toJSONString 不一致
环境信息
请填写以下信息:
重现步骤
期待的正确结果
两者结果不一致
result:
org.opentest4j.AssertionFailedError:
Expected :"Rejected"
Actual :"REJECTED"
The text was updated successfully, but these errors were encountered: