zoukankan      html  css  js  c++  java
  • fastjson将对象和json互转,@JSONField的使用及不生效

    <!-- 9.fastjson -->
                <dependency>
                    <groupId>com.alibaba</groupId>
                    <artifactId>fastjson</artifactId>
                    <version>1.2.47</version>
                </dependency>

     

    jsonArray.toJsonString(object)默认首字母小写,但是有些时候,不想要这种默认机制,可以在实体类上加上@JSONField

    package com.hainei.pojo.bo.toZonesData;
    
    import com.alibaba.fastjson.annotation.JSONField;
    import lombok.Data;
    
    /**
     * Created with IntelliJ IDEA.
     * User:wq
     * Date:2020/12/19
     * Time: 15:19
     * Description: 10.1作业人员在岗在位数据
     */
    @Data
    public class ZonesWorkPeoleBO {
    
        @JSONField(name = "QYBM")
        private String QYBM;
    
        @JSONField(name = "GWID")
        private String GWID;
    
        @JSONField(name = "GWMC")
        private String GWMC;
    
        @JSONField(name = "GWDD")
        private String GWDD;
    
        @JSONField(name = "GWSJ")
        private String GWSJ;
    
        @JSONField(name = "RYBMA")
        private String RYBMA;
    
        @JSONField(name = "RYXM")
        private String RYXM;
    
        @JSONField(name = "ZGRYSL")
        private String ZGRYSL;
    
        @JSONField(name = "RCSJ")
        private String RCSJ;
    
        @JSONField(name = "LCSJ")
        private String LCSJ;
    
        @JSONField(name = "STATUS")
        private Integer STATUS;
    
        private String createDate ;
    
        private String createBy;
    
        private String updateDate ;
    
        private String updateBy;
    
        private Integer Version;
    
        private Integer isHistory;
    
        private Integer Sync;
    
        private String syncDate;
    }
    View Code

    光这样还不行,要替换springBoot的默认json转化机制,需要在启动类App中注入一个bean。这样才能生效。

    @Bean
        public HttpMessageConverters fastJsonHttpMessageConverters() {
            FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
            FastJsonConfig fastJsonConfig = new FastJsonConfig();
            fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
            fastConverter.setFastJsonConfig(fastJsonConfig);
            HttpMessageConverter<?> converter = fastConverter;
            return new HttpMessageConverters(converter);
        }

    https://www.cnblogs.com/h-java/p/10220737.html

     https://www.liangzl.com/get-article-detail-9315.html

  • 相关阅读:
    新浪微博评论抓取
    ubuntu下ssh登录特别慢的问题
    在ubuntu13.04上安装Mac主题
    ubuntu修复grub
    linux卸载自己编译安装的内核
    ubuntu下搭建sublime text2的java开发环境
    CentOS防火墙对特定端口允许
    python笔记:python的表达式
    python笔记一:python变量
    python笔记一:python初步
  • 原文地址:https://www.cnblogs.com/wq-9/p/14140771.html
Copyright © 2011-2022 走看看