@Configuration
public class FastJsonSerializeConfig {
@Bean("snakeCaseSerializeConfig")
@Scope("singleton")
public SerializeConfig snakeCaseSerializeConfig() {
SerializeConfig config = new SerializeConfig();
config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
return config;
}
@Bean("pascalCasSerializeConfig")
@Scope("singleton")
public SerializeConfig pascalCasSerializeConfig() {
SerializeConfig config = new SerializeConfig();
config.propertyNamingStrategy = PropertyNamingStrategy.PascalCase;
return config;
}
}
修改全局缺省的命名策略
SerializeConfig.getGlobalInstance()
.propertyNamingStrategy = PropertyNamingStrategy.PascalCase;
另外由于fastjson的策略是枚举方式,暂时不支持自定义新的统一的属性名策略,如果有其他需求可以通过
@JSONField(name = "xxx")来指定每个属性的名称