From 35b3ab937bc93e1349797533ca4bf925d1442bff Mon Sep 17 00:00:00 2001 From: "swapdewalkar@gmail.com" Date: Tue, 26 Mar 2024 17:26:04 +0530 Subject: [PATCH] #4486: Remove Trailing zeros for decimals/float --- src/main/java/com/alibaba/fastjson/JSON.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/alibaba/fastjson/JSON.java b/src/main/java/com/alibaba/fastjson/JSON.java index 6159c72b1b..58be1d984d 100644 --- a/src/main/java/com/alibaba/fastjson/JSON.java +++ b/src/main/java/com/alibaba/fastjson/JSON.java @@ -703,6 +703,12 @@ public static String toJSONString(Object object, int defaultFeatures, Serializer serializer.write(object); String outString = out.toString(); int len = outString.length(); + while (len > 0 + && outString.charAt(len - 1) == '0' + && object instanceof Number + && !out.isEnabled(SerializerFeature.WriteClassName)) { + len--; + } if (len > 0 && outString.charAt(len -1) == '.' && object instanceof Number