|
@@ -0,0 +1,57 @@
|
|
|
+package com.sagacloud.utils;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import org.json.JSONArray;
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by wo on 5/2/18.
|
|
|
+ */
|
|
|
+public class VendersUtil {
|
|
|
+
|
|
|
+ public static JSONObject successJsonMsg(String msg) {
|
|
|
+ JSONObject jsonObj = new JSONObject();
|
|
|
+ jsonObj.put("result", "success");
|
|
|
+ jsonObj.put("resultMsg", msg);
|
|
|
+ return jsonObj;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static JSONObject successJsonMsg(String msg, Object pojo) throws JsonProcessingException {
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ if(pojo != null){
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ obj = new JSONObject(mapper.writeValueAsString(pojo));
|
|
|
+ }
|
|
|
+ JSONObject jsonObj = new JSONObject();
|
|
|
+ jsonObj.put("result", "success");
|
|
|
+ jsonObj.put("resultMsg", msg);
|
|
|
+ jsonObj.put("content",obj);
|
|
|
+ return jsonObj;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static JSONObject successJsonMsg(String msg, List list) {
|
|
|
+ JSONObject jsonObj = new JSONObject();
|
|
|
+ jsonObj.put("result", "success");
|
|
|
+ jsonObj.put("count",list.size());
|
|
|
+ jsonObj.put("content",new JSONArray(list));
|
|
|
+ jsonObj.put("resultMsg", msg);
|
|
|
+ return jsonObj;
|
|
|
+ }
|
|
|
+ public static JSONObject successJsonMsg(String msg, JSONArray arr){
|
|
|
+ JSONObject jsonObj = new JSONObject();
|
|
|
+ jsonObj.put("result", "success");
|
|
|
+ jsonObj.put("count",arr.length());
|
|
|
+ jsonObj.put("content",arr);
|
|
|
+ jsonObj.put("resultMsg", msg);
|
|
|
+ return jsonObj;
|
|
|
+ }
|
|
|
+ public static JSONObject errorJsonMsg(String msg) {
|
|
|
+ JSONObject jsonObj = new JSONObject();
|
|
|
+ jsonObj.put("result", "failure");
|
|
|
+ jsonObj.put("resultMsg", msg);
|
|
|
+ return jsonObj;
|
|
|
+ }
|
|
|
+}
|