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

[BUG] 使用 @JSONType(writeEnumAsJavaBean = true) 序列化枚举,与期待结果不一致 #730

Closed
caryyin opened this issue Sep 2, 2022 · 3 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@caryyin
Copy link

caryyin commented Sep 2, 2022

问题描述

使用 @JSONType(writeEnumAsJavaBean = true) 序列化枚举,与期待结果不一致

环境信息

请填写以下信息:

  • OS信息: [e.g.:win10]
  • JDK信息: [e.g.:jdk1.8.0_45]
  • 版本信息:[e.g.:Fastjson2 2.0.12]

重现步骤

如何操作可以重现该问题:

  1. 执行单元测试 test_serializeEnumAsJavaBean() 方法
package com.alibaba.fastjson2.v1issues.issue_1400;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.annotation.JSONType;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class OrderTypeTest {

    @Test
    public void test_serializeEnumAsJavaBean() {
        String text = JSON.toJSONString(OrderType.PayOrder);
        assertEquals("{\"remark\":\"支付订单\",\"value\":1}", text);
    }

    @JSONType(writeEnumAsJavaBean = true)
    public enum OrderType {

        PayOrder(1, "支付订单"), //
        SettleBill(2, "结算单");

        public final int value;
        public final String remark;

        OrderType(int value, String remark) {
            this.value = value;
            this.remark = remark;
        }
    }
}

期待的正确结果

预期:{"remark":"支付订单","value":1}

实际结果

实际:"PayOrder"

image

@caryyin caryyin added the bug Something isn't working label Sep 2, 2022
@wenshao
Copy link
Member

wenshao commented Sep 2, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.13-SNAPSHOT/
问题已经修复,请用2.0.13-SNAPSHOT版本帮忙验证,2.0.13版本预计9月12日发布

@wenshao wenshao added the fixed label Sep 2, 2022
@wenshao wenshao added this to the 2.0.13 milestone Sep 2, 2022
@wenshao
Copy link
Member

wenshao commented Sep 10, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.13
2.0.13版本已经发布,请用帮忙用新版本验证

@wenshao wenshao closed this as completed Sep 10, 2022
@zhrgithub
Copy link

zhrgithub commented Sep 10, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

3 participants