| | |
| | | import java.security.MessageDigest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.text.DateFormat; |
| | | import java.util.Collection; |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | |
| | | String st = ""; |
| | | for (int i = 0; i < srcList.size(); i++) { |
| | | st += srcList.get(i) + seperate; |
| | | } |
| | | if (st.endsWith(seperate)) { |
| | | st = st.substring(0, st.length() - seperate.length()); |
| | | } |
| | | return st; |
| | | } |
| | | |
| | | |
| | | public static String join(Collection srcList, String seperate) { |
| | | String st = ""; |
| | | for (Iterator<String> its = srcList.iterator(); its.hasNext(); ) { |
| | | st += its.next() + seperate; |
| | | } |
| | | if (st.endsWith(seperate)) { |
| | | st = st.substring(0, st.length() - seperate.length()); |
| | |
| | | } else { |
| | | Gson gson = new GsonBuilder().enableComplexMapKeySerialization().excludeFieldsWithoutExposeAnnotation() |
| | | .setDateFormat(DateFormat.LONG).registerTypeAdapter(Date.class, new JsonSerializer<Date>() { |
| | | @Override |
| | | public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { |
| | | if (value == null) { |
| | | return new JsonPrimitive("0"); |
| | | } else { |
| | | return new JsonPrimitive(value.getTime()); |
| | | } |
| | | } |
| | | }).setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)// 会把字段首字母大写 |
| | | @Override |
| | | public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { |
| | | if (value == null) { |
| | | return new JsonPrimitive("0"); |
| | | } else { |
| | | return new JsonPrimitive(value.getTime()); |
| | | } |
| | | } |
| | | }).setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)// 会把字段首字母大写 |
| | | .setPrettyPrinting().setVersion(1.0).create(); |
| | | String st = gson.toJson(o); |
| | | return Utils.JsonFilter(st); |