Skip to content

Commit

Permalink
Merge branch '1.7.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
shakuzen committed Aug 26, 2021
2 parents 423fe98 + 6d6cc96 commit f8b692d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,73 +15,22 @@
*/
package io.micrometer.core.instrument.util;

/**
* @deprecated this will be removed and should not be used
*/
@Deprecated
public final class JsonUtils {

private JsonUtils() {
}

/**
* Based on https://stackoverflow.com/a/49564514/510017
*
* @param unformattedJsonString JSON string that has not been formatted at all.
* @return A best-effort at pretty printed JSON, even for malformed JSON.
* @return the input string unchanged
* @deprecated this will be removed and no longer does anything meaningful
*/
@Deprecated
public static String prettyPrint(String unformattedJsonString) {
StringBuilder sb = new StringBuilder();
int indentLevel = 0;
boolean inQuote = false;
for (char charFromUnformattedJson : unformattedJsonString.toCharArray()) {
switch (charFromUnformattedJson) {
case '"':
// switch the quoting status
inQuote = !inQuote;
sb.append(charFromUnformattedJson);
break;
case ' ':
// For space: ignore the space if it is not being quoted.
if (inQuote) {
sb.append(charFromUnformattedJson);
}
break;
case '{':
case '[':
// Starting a new block: increase the indent level
sb.append(charFromUnformattedJson);
indentLevel++;
appendIndentedNewLine(indentLevel, sb);
break;
case '}':
case ']':
// Ending a new block; decrese the indent level
indentLevel--;
appendIndentedNewLine(indentLevel, sb);
sb.append(charFromUnformattedJson);
break;
case ',':
// Ending a json item; create a new line after
sb.append(charFromUnformattedJson);
if (!inQuote) {
appendIndentedNewLine(indentLevel, sb);
}
break;
default:
sb.append(charFromUnformattedJson);
}
}
return sb.toString();
}

/**
* Print a new line with indention at the beginning of the new line.
*
* @param indentLevel The indention level to use.
* @param stringBuilder The string builder to append it to.
*/
private static void appendIndentedNewLine(int indentLevel, StringBuilder stringBuilder) {
stringBuilder.append("\n");
for (int i = 0; i < indentLevel; i++) {
// Assuming indention using 2 spaces
stringBuilder.append(" ");
}
return unformattedJsonString;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package io.micrometer.core.ipc.http;

import io.micrometer.core.instrument.util.JsonUtils;
import io.micrometer.core.instrument.util.StringUtils;
import io.micrometer.core.lang.Nullable;

Expand Down Expand Up @@ -111,8 +110,6 @@ public String toString() {
.append(url.toString()).append("\n");
if (entity.length == 0) {
printed.append("<no request body>");
} else if ("application/json".equals(requestHeaders.get("Content-Type"))) {
printed.append(JsonUtils.prettyPrint(new String(entity)));
} else {
printed.append(new String(entity));
}
Expand Down

0 comments on commit f8b692d

Please sign in to comment.