将map转化为json

@param map
@return
8186
public String formatMap2JSON(Map<String, Object> map) {
		StringWriter stringWriter = new StringWriter();
		String json = "";
		try {
			JsonGenerator gen = new JsonFactory()
					.createJsonGenerator(stringWriter);
			MAPPER.writeValue(gen, map);
			gen.close();
			json = stringWriter.toString();
		} catch (Exception e) {
			LOGGER.error("", e);
		}
		return json;
	}
670647
public Map<String, Object> jsonToMap(String json) {

        /*
         * This if block treats the /v2/accounts/exists response. Currently the endpoint returns the status
         * code on its response body, breaking the JSON conversion.
         */
        if ("200".equals(json)) {
            this.responseBody.put("code", 200);
            return this.responseBody;
        }

        if ("400".equals(json)) {
            this.responseBody.put("code", 400);
            return this.responseBody;
        }

        if ("404".equals(json)) {
            this.responseBody.put("code", 404);
            return this.responseBody;
        }

        if (!json.equals("")) {
            ObjectMapper mapper = new ObjectMapper();
            try {
                this.responseBody = mapper.readValue(json, new TypeReference<Map<String, Object>>(){});
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return this.responseBody;
    }
843118
@Override
    public String serialize(Map<String, String> map) {

        try {

            // the format is based on the properties output format
            Properties props = new Properties();
            props.putAll(map);
            Writer writer = new StringWriter();
            props.store(writer, null);

            // we need a list of strings so we can further process the format
            List<String> lines = new ArrayList<String>();
            for (String line : writer.toString().split("\r?\n")) {
                // comments and empty lines are skipped
                if (!line.trim().isEmpty() && !line.trim().startsWith("#")) {
                    lines.add(line.trim());
                }
            }

            // sort by key so create a canonical format
            Collections.sort(lines);

            // build the output string
            StringBuilder builder = new StringBuilder();
            for (String line : lines) {

                if (multiline) {
                    if (builder.length() > 0) {
                        builder.append(lineSeparator);
                    }
                    builder.append(line);
                }
                else {
                    if (builder.length() > 0) {
                        builder.append("&");
                    }
                    builder.append(line.replace("&", "\\u0026"));
                }

            }
            return builder.toString();

        } catch (IOException e) {
            throw new IllegalStateException(e);
        }

    }
1119611
private static Map<String, Map<String, String>> getStatsMap(String json)
      throws IOException {
    if (json == null || json.isEmpty()) {
      return new HashMap<String, Map<String, String>>();
    }
    TypeReference<Map<String, Map<String, String>>> type = new TypeReference<Map<String, Map<String, String>>>() {
    };
    return mapper.readValue(json, type);
  }
1286741
private String convertToJson(Map<String, ?> map) throws MovieDbException {
        try {
            return MAPPER.writeValueAsString(map);
        } catch (JsonProcessingException ex) {
            throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "JSON conversion failed", "", ex);
        }
    }
236870
@JsonIgnore
    @SuppressWarnings("unchecked")
    public Map<String, Object> getDataMap() {
        if (data instanceof Map) {
            return (Map<String, Object>) data;
        }
        return Collections.emptyMap();
    }
862554
private static String getOrderedMapString(Map<Object, Object> map) {
		ArrayList<String> list = new ArrayList<String>();
		for (Map.Entry<Object, Object> entry : map.entrySet()) {
			if (entry.getValue() != null) {
				Object key = entry.getKey();
				Object value = entry.getValue();
				String objectString = getObjectString(value);
				if (!StringUtils.isEmpty(objectString)) {
					list.add(getObjectString(key) + "=" + objectString + "&");
				}

			}
		}
		int size = list.size();
		String[] arrayToSort = list.toArray(new String[size]);
		Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < size; i++) {
			sb.append(arrayToSort[i]);
		}
		return "{" + sb.toString() + "}";
	}
1045182
@SuppressWarnings("static-method")
	protected String generateJson(Map<String, Object> map) throws JsonProcessingException {
		final ObjectMapper mapper = new ObjectMapper();
		return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map);
	}
880294
public static String stringForMap(Map<Object, Object> map) {
        StringBuilder sbOutput = new StringBuilder();
        if (map == null) {
            sbOutput.append("\tNULL");
        } else {
            for (Entry<Object, Object> entry : map.entrySet()) {
                sbOutput.append('\t').append(entry).append('\n');
            }
        }
        return sbOutput.toString();
    }
679303
private String getJSONFromMap(Map<String, Object> propMap) {
        try {
            return new JSONObject(propMap).toString();
        } catch (Exception e) {
            return "{}";
        }
    }
250909
private String _serializeMap(Map map, Set<Object> done) throws ConverterException {
	StringBuilder sb = new StringBuilder(goIn() + "<struct>");

	Iterator it = map.keySet().iterator();

	deep++;
	while (it.hasNext()) {
	    Object key = it.next();
	    sb.append(goIn() + "<var name=" + del + XMLUtil.escapeXMLString(key.toString()) + del + ">");
	    sb.append(_serialize(map.get(key), done));
	    sb.append(goIn() + "</var>");
	}
	deep--;

	sb.append(goIn() + "</struct>");
	return sb.toString();
    }
394677
public static String mapToJson(final Map<String, Object> map) {
        try {
            return MAPPER.writeValueAsString(map);
        } catch (JsonProcessingException e) {
            return null;
        }
    }
1003787
function (mapping) {
    const result = {};
    for (const [key, value] of _.toPairs(mapping)) {
      result[key] = _.isString(value) ? value : JSON.stringify(value);
    }
    return result;
  }
139462
@Nullable
    public String toJson(@Nullable Map<String, Object> map) {
        if (map == null || map.isEmpty()) {
            return null;
        }

        try (StringWriter writer = new StringWriter(bufferSize)) {
            objectMapper.writeValue(writer, map);
            if (doesAppendLineSeparator) {
                writer.append(CoreConstants.LINE_SEPARATOR);
            }
            return writer.toString();
        } catch (IOException e) {
            throw new IllegalArgumentException("Unable to format map as a JSON", e);
        }
    }
347788
public static Map<String, Object> newFlatKeyMap(Map<String, ?> map) {
        return newFlatKeyMap(new HashMap<>(), map);
    }
1327005
@Nullable
    static Map<String, Object> jsonObjectToMap(@Nullable JSONObject jsonObject) {
        if (jsonObject == null) {
            return null;
        }
        Map<String, Object> map = new HashMap<>();
        Iterator<String> keyIterator = jsonObject.keys();
        while (keyIterator.hasNext()) {
            String key = keyIterator.next();
            Object value = jsonObject.opt(key);
            if (NULL.equals(value) || value == null) {
                continue;
            }

            if (value instanceof JSONObject) {
                map.put(key, jsonObjectToMap((JSONObject) value));
            } else if (value instanceof JSONArray) {
                map.put(key, jsonArrayToList((JSONArray) value));
            } else {
                map.put(key, value);
            }
        }
        return map;
    }
922017
public static Map<String, String> serialize(Map<String, Object> map, String prefix) {
        if (map == null || map.isEmpty()) {
            return Collections.emptyMap();
        }

        Map<String, String> flattened = flatten(map, new HashMap<String, String>(), new ArrayList<String>());

        Map<String, String> result = new HashMap<>();
        for (Map.Entry<String, String> entry : flattened.entrySet()) {
            result.put(prefix + "." + entry.getKey(), entry.getValue());
        }

        return result;
    }