Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[FEATURE] 兼容API序列化输出兼容1.x的命名策略 #1022

Closed
wenshao opened this issue Dec 18, 2022 · 0 comments
Closed

[FEATURE] 兼容API序列化输出兼容1.x的命名策略 #1022

wenshao opened this issue Dec 18, 2022 · 0 comments
Labels
enhancement New feature or request fixed
Milestone

Comments

@wenshao
Copy link
Member

wenshao commented Dec 18, 2022

FASTJSON 2缺省使用java.beans.Introspector#decapitalize一致的规则处理getter和setter,这个会导致和fastjson 1.x不兼容。需要修改为在兼容API中使用和fastjson 1.x一致的命名规则。

如下:

public class NamingTest {
    @Test
    public void test() {
        Bean bean = new Bean();
        bean.oAuth = "abc";

        assertEquals(
            "{\"oAuth\":\"abc\"}", 
            com.alibaba.fastjson.JSON.toJSONString(bean)
        );

        assertEquals(
            "{\"OAuth\":\"abc\"}", 
            com.alibaba.fastjson2.JSON.toJSONString(bean)
        );
    }

    public static class Bean {
        private String oAuth;

        public String getOAuth() {
            return oAuth;
        }

        public void setOAuth(String oAuth) {
            this.oAuth = oAuth;
        }
    }
}
@wenshao wenshao added the enhancement New feature or request label Dec 18, 2022
@wenshao wenshao added this to the 2.0.22 milestone Dec 18, 2022
@wenshao wenshao changed the title [FEATURE] 兼容API序列化输出兼容1.x的命名小邪策略 [FEATURE] 兼容API序列化输出兼容1.x的命名策略 Dec 18, 2022
@wenshao wenshao added the fixed label Dec 18, 2022
@wenshao wenshao closed this as completed Dec 31, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request fixed
Projects
None yet
Development

No branches or pull requests

1 participant