Java Code Examples for net.minidev.json.JSONValue#escape()

The following examples show how to use net.minidev.json.JSONValue#escape() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonWriter.java    From json-smart-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * Write a Key : value entry to a stream
 */
public static void writeJSONKV(String key, Object value, Appendable out, JSONStyle compression) throws IOException {
	if (key == null)
		out.append("null");
	else if (!compression.mustProtectKey(key))
		out.append(key);
	else {
		out.append('"');
		JSONValue.escape(key, out, compression);
		out.append('"');
	}
	compression.objectEndOfKey(out);
	if (value instanceof String) {
		compression.writeString(out, (String) value);
	} else
		JSONValue.writeJSONString(value, out, compression);
	compression.objectElmStop(out);
}
 
Example 2
Source File: CatalogRestUtils.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a JSON string for the Difference statements in the specified RDF format. Key "additions" has value of the
 * Difference's addition statements and key "deletions" has value of the Difference's deletion statements.
 *
 * @param difference   The Difference to convert into a JSONObject.
 * @param format       A String representing the RDF format to return the statements in.
 * @param transformer  The {@link SesameTransformer} to use.
 * @param bNodeService The {@link BNodeService} to use.
 * @return A JSONObject with a key for the Difference's addition statements and a key for the Difference's deletion
 * statements.
 */
public static String getDifferenceJsonString(Difference difference, String format, SesameTransformer transformer,
                                             BNodeService bNodeService) {
    String additions = modelToSkolemizedString(difference.getAdditions(), format, transformer, bNodeService);
    String deletions = modelToSkolemizedString(difference.getDeletions(), format, transformer, bNodeService);


    return "{ \"additions\": "
            + (format.toLowerCase().contains("json") ? additions : "\"" + JSONValue.escape(additions) + "\"")
            + ", \"deletions\": "
            + (format.toLowerCase().contains("json") ? deletions : "\"" + JSONValue.escape(deletions) + "\"")
            + " }";

}
 
Example 3
Source File: CompessorMapper.java    From json-smart-v2 with Apache License 2.0 5 votes vote down vote up
private void startKey(String key) throws IOException {
	addComma();
	// if (key == null)
	// return;
	if (isArray())
		return;
	if (!compression.mustProtectKey(key))
		out.append(key);
	else {
		out.append('"');
		JSONValue.escape(key, out, compression);
		out.append('"');
	}
	out.append(':');
}
 
Example 4
Source File: SerializedSkin.java    From Protocol with Apache License 2.0 4 votes vote down vote up
private static String convertLegacyGeometryName(String geometryName) {
    return "{\"geometry\" : {\"default\" : \"" + JSONValue.escape(geometryName) + "\"}}";
}
 
Example 5
Source File: JsonUtils.java    From karate with MIT License 4 votes vote down vote up
public static String escapeValue(String raw) {
    return JSONValue.escape(raw, JSONStyle.LT_COMPRESS);
}
 
Example 6
Source File: Match.java    From karate with MIT License 4 votes vote down vote up
public static String quote(String exp) {
    return exp == null ? "null" : "\"" + JSONValue.escape(exp) + "\"";
}