fastjson 出现首字母小写的问题


  今天工作使用fastjson要求传过去的参数全为大写,在使用的过程中发现它自动将我的字段首字母转为小写了,在网上查了一些资料,发现下面的这个挺好,比其他的要方便。

package com.alibaba.fastjson.serializer;

public class PascalNameFilter implements NameFilter {

    public String process(Object source, String name, Object value) {
        if (name == null || name.length() == 0) {
            return name;
        }

        char[] chars = name.toCharArray();
        chars[0]= Character.toUpperCase(chars[0]);

        String pascalName = new String(chars);
        return pascalName;
    }
}

 可以通过一个简单的参数来解决

  info是我的一个对象,

JSON.toJSONString(info,new PascalNameFilter());

 

参考了该博主的博客:https://blog.csdn.net/cjavahello/article/details/74931730

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM