Explorar o código

改用JSONObject.toJSONString

menglu %!s(int64=4) %!d(string=hai) anos
pai
achega
e0de481463

+ 2 - 2
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/data/SceneDataObject.java

@@ -6,8 +6,8 @@ import java.util.Map;
 import java.util.Set;
 
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.persagy.ibms.data.sdk.util.Constant;
-import com.persagy.ibms.data.sdk.util.FastJsonUtil;
 import com.persagy.ibms.data.sdk.util.Repository;
 
 public class SceneDataObject {
@@ -62,7 +62,7 @@ public class SceneDataObject {
 
 	@Override
 	public String toString() {
-		return FastJsonUtil.toString(this.toJSON(1));
+		return JSONObject.toJSONString(this.toJSON(1), SerializerFeature.WriteMapNullValue);
 	}
 
 	public Set<String> keySet() {

+ 3 - 2
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/data/SceneDataSet.java

@@ -5,7 +5,8 @@ import java.util.List;
 import java.util.Map;
 
 import com.alibaba.fastjson.JSONArray;
-import com.persagy.ibms.data.sdk.util.FastJsonUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.serializer.SerializerFeature;
 
 public class SceneDataSet {
 	public boolean isSingleValueSet = false;
@@ -66,6 +67,6 @@ public class SceneDataSet {
 
 	@Override
 	public String toString() {
-		return FastJsonUtil.toString(this.toJSON(1));
+		return JSONObject.toJSONString(this.toJSON(1), SerializerFeature.WriteMapNullValue);
 	}
 }

+ 2 - 2
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/data/SceneDataValue.java

@@ -2,7 +2,7 @@ package com.persagy.ibms.data.sdk.data;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.persagy.ibms.data.sdk.util.FastJsonUtil;
+import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.persagy.ibms.data.sdk.util.Repository;
 
 public class SceneDataValue {
@@ -84,6 +84,6 @@ public class SceneDataValue {
 
 	@Override
 	public String toString() {
-		return FastJsonUtil.toString(this.toJSON(true, 1));
+		return JSONObject.toJSONString(this.toJSON(true, 1), SerializerFeature.WriteMapNullValue);
 	}
 }

+ 7 - 6
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestUtil.java

@@ -14,6 +14,7 @@ import javax.servlet.http.HttpServletRequest;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.persagy.ibms.data.sdk.data.SceneDataObject;
 import com.persagy.ibms.data.sdk.data.SceneDataPrimitive;
 import com.persagy.ibms.data.sdk.data.SceneDataSet;
@@ -51,19 +52,19 @@ public class RestUtil {
 				JSONArray array = (JSONArray) Content;
 				result.put("Count", array.size());
 			}
-			return FastJsonUtil.toFormatString(Content);
+			return JSONObject.toJSONString(Content, SerializerFeature.WriteMapNullValue);
 		} catch (Exception e) {
 			e.printStackTrace();
 			result.put("Result", "failure");
 			result.put("Reason", LogUtil.GetExceptionStackTrace(e));
 		}
-		return FastJsonUtil.toFormatString(result);
+		return JSONObject.toJSONString(result, SerializerFeature.WriteMapNullValue);
 	}
 
 	public static String showTree() {
 		Repository Repository = RepositoryBase.instance;
 		JSONObject JSON = (JSONObject) Repository.objectData.toJSON(-1);
-		return FastJsonUtil.toFormatString(JSON);
+		return JSONObject.toJSONString(JSON, SerializerFeature.WriteMapNullValue);
 	}
 
 	public static String check() {
@@ -263,7 +264,7 @@ public class RestUtil {
 		try {
 			Object valueObject = ComputeUtil.getValueObject(Repository, valuePath);
 			Object valueJSON = ComputeUtil.getValueJSON(valueObject, read_level);
-			return FastJsonUtil.toString(valueJSON);
+			return JSONObject.toJSONString(valueJSON, SerializerFeature.WriteMapNullValue);
 		} catch (Exception e) {
 			e.printStackTrace();
 			String message = LogUtil.GetExceptionStackTrace(e);
@@ -290,12 +291,12 @@ public class RestUtil {
 						.ReadJSONObject(new File(Constant.GetPath() + Constant.getSeperator() + "work_order_sample.json"));
 				JSONArray work_orders = new JSONArray();
 				work_orders.add(work_order);
-				return FastJsonUtil.toString(work_orders);
+				return JSONObject.toJSONString(work_orders, SerializerFeature.WriteMapNullValue);
 			} else {
 				Object valueObject = ComputeUtil.getValueObject(Repository, valuePath);
 				RecursiveUtil.refreshObject(Repository, valueObject);
 				Object valueJSON = ComputeUtil.getValueJSON(valueObject);
-				return FastJsonUtil.toString(valueJSON);
+				return JSONObject.toJSONString(valueJSON, SerializerFeature.WriteMapNullValue);
 			}
 		} catch (Exception e) {
 			e.printStackTrace();

+ 5 - 2
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/FastJsonUtil.java

@@ -16,6 +16,7 @@ import java.util.Set;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.serializer.SerializerFeature;
 
 public class FastJsonUtil {
 	public static Set<Object> ValueArray2ValueSet(JSONArray valueArray) {
@@ -238,7 +239,8 @@ public class FastJsonUtil {
 			} else if (item instanceof BigInteger) {
 				return ((BigInteger) item).longValue();
 			} else {
-				throw new Exception("FastJsonUtil: " + "JSON property " + name + " cant Cast to Long:" + FastJsonUtil.toFormatString(json));
+				throw new Exception("FastJsonUtil: " + "JSON property " + name + " cant Cast to Long:"
+						+ JSONObject.toJSONString(json, SerializerFeature.WriteMapNullValue));
 			}
 		} else {
 			return null;
@@ -261,7 +263,8 @@ public class FastJsonUtil {
 			} else if (item instanceof BigDecimal) {
 				return ((BigDecimal) item).longValue();
 			} else {
-				throw new Exception("FastJsonUtil: " + "JSON property " + name + " cant Cast to Double:" + FastJsonUtil.toFormatString(json));
+				throw new Exception("FastJsonUtil: " + "JSON property " + name + " cant Cast to Double:"
+						+ JSONObject.toJSONString(json, SerializerFeature.WriteMapNullValue));
 			}
 		} else {
 			return null;

+ 4 - 3
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/ToolUtil.java

@@ -6,6 +6,7 @@ import java.util.Map;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.persagy.ibms.data.sdk.service.rest.RestUtil;
 
 public class ToolUtil {
@@ -133,7 +134,7 @@ public class ToolUtil {
 			if (is_public) {
 				String floor = SELTCC2floor.get(SELTCC);
 				if (floor != null) {
-					String floorName=(String)floorMap.get(floor).get("localName");
+					String floorName = (String) floorMap.get(floor).get("localName");
 					String level1id = ids[index_level];
 					String level1name = levels[index_level];
 					String level2id = ids[index_level] + "-" + floorMap.get(floor).get("localId") + "-" + types[index_type];
@@ -143,7 +144,7 @@ public class ToolUtil {
 					item.put("二级编组", level2id);
 					item.put("二级编组名称", level2name);
 					item.put("一级编组", level1id);
-					item.put("一级编组名称", level1name); 
+					item.put("一级编组名称", level1name);
 					huiluArray.add(item);
 					if (!level1Map.containsKey(level1id)) {
 						level1Map.put(level1id, true);
@@ -199,7 +200,7 @@ public class ToolUtil {
 		result.put("回路", huiluArray);
 		result.put("一级编组", level1Array);
 		result.put("二级编组", level2Array);
-		return FastJsonUtil.toFormatString(result);
+		return JSONObject.toJSONString(result, SerializerFeature.WriteMapNullValue);
 	}
 
 	public static JSONArray getArray_relation(String graphCode, String relCode, String relValue) {