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] 无法拦截非 Serializable 的类进行序列化 #756

Closed
AlbumenJ opened this issue Sep 12, 2022 · 2 comments
Closed

[BUG] 无法拦截非 Serializable 的类进行序列化 #756

AlbumenJ opened this issue Sep 12, 2022 · 2 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@AlbumenJ
Copy link

问题描述

简要描述您碰到的问题。
无法拦截非 Serializable 的类进行序列化

环境信息

请填写以下信息:

  • 版本信息:Fastjson2 2.0.13

重现步骤

    public static void main(String[] args) {
        NoneSerializable noneSerializable = new NoneSerializable();
        noneSerializable.setParam("Test");
        byte[] bytes = JSONB.toBytes(noneSerializable, JSONWriter.Feature.WriteClassName);
        Object o = JSONB.parseObject(bytes, Object.class, JSONReader.Feature.SupportAutoType);
        System.out.println(o);
    }

    public static class NoneSerializable {
        private String param;

        public String getParam() {
            return param;
        }

        public void setParam(String param) {
            this.param = param;
        }
    }
@AlbumenJ AlbumenJ added the bug Something isn't working label Sep 12, 2022
@wenshao
Copy link
Member

wenshao commented Sep 12, 2022

   @Test
    public void test() {
        NoneSerializable noneSerializable = new NoneSerializable();
        noneSerializable.setParam("Test");
        byte[] bytes = JSONB.toBytes(noneSerializable, JSONWriter.Feature.WriteClassName, JSONWriter.Feature.IgnoreNoneSerializable);
        Object o = JSONB.parseObject(bytes, Object.class, JSONReader.Feature.SupportAutoType);
        assertNull(o);
    }

    public static class NoneSerializable {
        private String param;

        public String getParam() {
            return param;
        }

        public void setParam(String param) {
            this.param = param;
        }
    }

需要加上 JSONWriter.Feature.IgnoreNoneSerializable

wenshao added a commit that referenced this issue Sep 12, 2022
wenshao added a commit that referenced this issue Sep 12, 2022
@wenshao wenshao added this to the 2.0.14 milestone Sep 12, 2022
@wenshao wenshao added the fixed label Sep 12, 2022
@wenshao
Copy link
Member

wenshao commented Sep 16, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.14
问题已修复,请用新版本

@wenshao wenshao closed this as completed Sep 16, 2022
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

2 participants