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

[FEATURE]JSONWriter.Feature 可以支持驼峰输出么 #3344

Open
scccy opened this issue Feb 20, 2025 · 2 comments
Open

[FEATURE]JSONWriter.Feature 可以支持驼峰输出么 #3344

scccy opened this issue Feb 20, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@scccy
Copy link

scccy commented Feb 20, 2025

请描述您的需求或者改进建议

对您想要需求或建议的清晰简洁的描述。
接收的数据是{
"data_list":"1"
}
返回的是{
"dataList": "1"
}
没有全局设置 要每个字段都要写 @JSONField(name = "data_list") 很累欸

@scccy scccy added the enhancement New feature or request label Feb 20, 2025
@wenshao
Copy link
Member

wenshao commented Feb 20, 2025

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.PropertyNamingStrategy;
import com.alibaba.fastjson2.filter.NameFilter;
import org.junit.jupiter.api.Test;

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

public class Issue3344 {
    @Test
    public void test() {
        Bean bean = new Bean();
        bean.userName = "DataWorks";
        String jsonString = JSON.toJSONString(bean, NameFilter.of(PropertyNamingStrategy.SnakeCase));
        assertEquals("{\"user_name\":\"DataWorks\"}", jsonString);
    }

    public static class Bean {
        public String userName;
    }
}

看这个是不是你想要的

wenshao added a commit that referenced this issue Feb 20, 2025
@scccy
Copy link
Author

scccy commented Feb 21, 2025

谢谢, config.setWriterFilters(NameFilter.of(PropertyNamingStrategy.SnakeCase));在这里成功了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants