Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Bug tracking library after FastJson omitted the decimal point 0     - 5 steps to help you become a good Docker contributors (Linux)

- Getting Started with Linux system to learn: how to check memory usage of Linux (Linux)

- Hands to teach you to solve Ubuntu error message (Linux)

- PostgreSQL-XL installation and deployment (Database)

- Manually compile Hadoop 2.6.0 under Ubuntu 14.04 (Server)

- MyEclipse configuration necessary (Linux)

- Ubuntu 12.04 64bit Install Source Insight 3.5 and create desktop icons (Linux)

- RHEL6.4 x86_64 build SVN service (Server)

- Incremental garbage collection mechanism for Ruby 2.2 (Programming)

- Partition and file system under Linux (Linux)

- BusyBox build root file system (Linux)

- Let VMware ESXi virtual switch support VLAN (Linux)

- Nodejs command-line program development tutorial (Programming)

- SSH does not require a password to log on to a Linux server (Server)

- MongoDB 3.0 New Features (Database)

- Hadoop 0.23 compile common errors (Server)

- VMware clone Linux find eth0 (Linux)

- 64 Ubuntu 15.04 Linux kernel upgrade to Linux 4.1.0 (Linux)

- MySQL IO SSD attempt at optimization (Database)

- Tmux Getting Start (Linux)

  Bug tracking library after FastJson omitted the decimal point 0
  Add Date : 2018-11-21      
  Recently used in the project FastJson library because FastJson Alibaba open source JSON toolkit processing JSON fast, performance is also very good, but powerful and fully support Java Bean, collection, Map, date, Enum, paradigm Wait.

But we use, we found a Bug:

Our interface defines a parameter of type float, but after the decimal point if you pass over the value is 0, then (such as 12.0), then the ".0" will be omitted. And this is unacceptable to us.

The following detailed description of this Bug, for example, the following code:

com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject ();
json.put ( "phone", "13911112222");

json.put ( "authCode", "285345");

json.put ( "deviceType", "phone");

json.put ( "myvalue", 12.0);

String json1 = json.toString ();

System.out.println ( "JSON ->" + json1);

The above code, the myvalue parameter is 12.0, but the result is the output of this code:

JSON -> { "authCode": "285345", "deviceType": "phone", "myvalue": 12, "phone": "13911112222"}
Visible. "0" is omitted.

 Tracking FastJson library source code, we found JSONObject class inherits from JSON class, and toString () method directly inherited parent class, without making coverage, continue to see toString () method JSON class and found this:


    public String toString () {

        return toJSONString ();


Direct call toJSONString () method. The toJSONString () method is this:

public String toJSONString () {

        SerializeWriter out = new SerializeWriter ();

        try {

            new JSONSerializer (out) .write (this);

            return out.toString ();

        } Finally {

            out.close ();



Continue to pursue, view SerializeWriter class source code, find writeFloatAndChar () method, as follows:

public void writeFloatAndChar (float value, char c) {

        String text = Float.toString (value);

        if (text.endsWith ( ". 0")) {

            text = text.substring (0, text.length () - 2);


        write (text);

        write (c);


To finally locate the reason for the float JSON value, if based on ".0" at the end, we cut off the end of the straight, so there is a scene at the beginning of this article.

Conclusion: Although this was not exactly the Bug, but the ".0" float at the end of this omission, and sometimes can not meet the business needs.
- Creating and extracting archives 11 tar command examples in Linux (Linux)
- Ubuntu 14.04 set auto sleep time (Linux)
- How common Linux automation tasks (Server)
- About DataGuard three protected mode test (Database)
- Nginx Load Balancing (standby) + Keepalived (Server)
- Linux installation notes under GAMIT (Linux)
- MySQL to NoSQL avatar (Database)
- Security: set limits on password (Linux)
- To achieve Linux Security (Linux)
- How SSHfs mount a remote file system on Linux (Linux)
- Ten minutes to find out the character set and character encoding (Linux)
- Improve the Ubuntu SSH login authentication approach speed (Linux)
- The difference between IPython and Python (Linux)
- Ubuntu install Wireshark (Linux)
- MySQLbinlog combat on using data recovery (Database)
- New experience Budgie (Budgerigar) desktop environment (Linux)
- MySQL tmpdir parameter modification (Database)
- To convert into a binary search tree sorted doubly linked list (Programming)
- using the ssh command to check the socket / Network Connections (Linux)
- Adjustment expand VMDK format VirtualBox disk space (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.