javabean转成json字符首字母大写

今天写接口的时候有个需求将接口返回的json字符串首字母大写:{"SN":"","Result":""}格式,
只需要在返回bean里面属性上加上@JsonProperty注解就可以了

import com.fasterxml.jackson.annotation.JsonProperty;
public class DiagResponeBean {
    @JsonProperty( "SN")
    private String sn;//设备sn
    @JsonProperty( "result")
    private String result;//响应诊断结果
    @JsonProperty( "Region")
    private String region;//管理域
   @JsonProperty( "Status")
    private String status;//设备状态
    //setter/getter
}
//controller 接口部分代码
 com.fasterxml.jackson.databind.ObjectMapper  ob =new  com.fasterxml.jackson.databind.ObjectMapper();
        //json转bean时忽略大小写
        ob.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
            if(StringUtil.isEmpty(json)){
                diagResponeBean.setSn("");
                diagResponeBean.setResult("入参不能为空");
                diagResponeBean.setRegion("");
                diagResponeBean.setStatus("");
                ob.writeValue(response.getOutputStream(), diagResponeBean);
                return;
            }

参考博文:
(1) https://blog.csdn.net/sinat_35605242/article/details/80826313

原文地址:https://www.cnblogs.com/jasonboren/p/12019537.html