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] Fastjson JSONField 异常 #2526

Closed
Cooper-Zhong opened this issue May 6, 2024 · 1 comment
Closed

[BUG] Fastjson JSONField 异常 #2526

Cooper-Zhong opened this issue May 6, 2024 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@Cooper-Zhong
Copy link

问题描述

#1258 在fastjson中有问题,fastjson2结果正常

环境信息

  • OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
  • JDK信息: [Openjdk 17.0.6]
  • 版本信息:[Fastjson 2.0.49]

重现步骤

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.annotation.JSONField;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.junit.jupiter.api.Test;

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

public class Issue1258Mutated_31 {

    @Getter
    @Setter
    @Data
    private class MutatedSimpleBean {
        @JSONField(name = "E")
        private Long et;
    }

    @Getter
    @Setter
    @Data
    private class MutatedSimpleBean1 {
        @com.alibaba.fastjson.annotation.JSONField(name = "E")
        private Long et;
    }

    @Test
    public void testMutated() {
        String str = "{\"E\":123,\"e\":\"abc\"}";
        MutatedSimpleBean bean = JSON.parseObject(str, MutatedSimpleBean.class);
        assertEquals(123L, bean.et);
    }

    @Test
    public void testMutatedfj() {
        String str = "{\"E\":123,\"e\":\"abc\"}";
        MutatedSimpleBean1 bean1 = com.alibaba.fastjson.JSON.parseObject(str, MutatedSimpleBean1.class);
        assertEquals(123L, bean1.et);
    }

    public static class MutatedBean {
        private Long et;

        public MutatedBean(@JSONField(name = "E") Long et) {
            this.et = et;
        }
    }

    public static class MutatedBean1 {
        private Long et;

        public MutatedBean1(@com.alibaba.fastjson.annotation.JSONField(name = "E") Long et) {
            this.et = et;
        }
    }

    @Test
    public void test2Mutated() {
        String str = "{\"E\":123,\"e\":\"abc\"}";
        MutatedBean bean = JSON.parseObject(str, MutatedBean.class);
        assertEquals(123L, bean.et);
    }

    @Test
    public void test2Mutatedfj() {
        String str = "{\"E\":123,\"e\":\"abc\"}";
        MutatedBean1 bean = com.alibaba.fastjson.JSON.parseObject(str, MutatedBean1.class);
        assertEquals(123L, bean.et);
    }
}

期待的正确结果

能够正常解析

相关日志输出

com.alibaba.fastjson.JSONException: parseLong error, value : abc
at com.alibaba.fastjson.JSON.parseObject(JSON.java:525)

@Cooper-Zhong Cooper-Zhong added the bug Something isn't working label May 6, 2024
@wenshao wenshao added this to the 2.0.50 milestone May 7, 2024
@wenshao
Copy link
Member

wenshao commented May 12, 2024

https://github.com/alibaba/fastjson2/releases/tag/2.0.50
2.0.50已发布,请用新版本

@wenshao wenshao closed this as completed May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants