zoukankan      html  css  js  c++  java
  • JSON.toJSONStringWithDateFormat 部分字段无法序列化

    FastJson相关介绍

    http://www.cnblogs.com/aliger/p/3916848.html

    问题解决办法

    实体类属性名驼峰写法,第一个驼峰前只有一个字母的属性无法序列化,如:uName (无法序列化) userName (可以序列化)
    环境:jdk1.8,junit 4.1.2, fastjson 1.1.26 mysql5.7

    错误重现

    *1建表语句
    DROP TABLE IF EXISTS mtt_member_new; CREATE TABLE mtt_member_new ( id int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID', un_name varchar(255) NOT NULL COMMENT '姓名', user_mobile int(20) DEFAULT NULL COMMENT '电话', u_email varchar(255) DEFAULT NULL COMMENT '电子邮箱', PRIMARY KEY (id), UNIQUE KEY username (un_name,user_mobile) ) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8

    *2实体类
    private Integer id;

    private String unName;
    
    private Integer userMobile;
    
    private String uEmail;
    

    *3 test测试类
    MttMemberNew member = mttMemberNewMapper.selectByPrimaryKey(11);

    logger.info(JSON.toJSONStringWithDateFormat(member, "yyyy-MM-dd HH:mm:ss"));

    *4 测试结果
    [org.junit.Test]{"id":11,"unName":"东魁","userMobile":13605715555}

    uEmail没有显示出来,可能是FastJson的BUG

  • 相关阅读:
    UML用例图总结
    项目管理心得:一个项目经理的个人体会、经验总结
    UML类图符号简介
    C++中栈和堆上建立对象的区别
    Win32 API
    Python
    remove extra kernel
    Create short cut
    Set Form Position
    Get folder
  • 原文地址:https://www.cnblogs.com/Bouger/p/7465361.html
Copyright © 2011-2022 走看看