SpanParser { public static String unescapeJson(String escaped) { if (escaped == null) { return null; } if (!containsChar(escaped, '\\')) { return escaped; } String unescaped = escaped; for (int i = 0; i < JSON_ESCAPE_CHAR_MAPPINGS.length; i++) { String escapedString = JSON_ESCAPE_CHAR_MAPPINGS[i]; if (escapedString != null) { String unescapedCharAsString = String.valueOf((char) i); unescaped = unescaped.replace(escapedString, unescapedCharAsString); } } return unescaped; } protected  SpanParser(); static String convertSpanToJSON(Span span); static Span fromJSON(String json); static String convertSpanToKeyValueFormat(Span span); static Span fromKeyValueString(String keyValueStr); static String escapeJson(String orig); static String unescapeJson(String escaped); static final String TRACE_ID_FIELD; static final String PARENT_SPAN_ID_FIELD; static final String SPAN_ID_FIELD; static final String SPAN_NAME_FIELD; static final String SAMPLEABLE_FIELD; static final String USER_ID_FIELD; static final String SPAN_PURPOSE_FIELD; static final String START_TIME_EPOCH_MICROS_FIELD; static final String DURATION_NANOS_FIELD; static final String TAGS_FIELD; static final String ANNOTATIONS_LIST_FIELD; static final String ANNOTATION_SUBOBJECT_TIMESTAMP_FIELD; static final String ANNOTATION_SUBOBJECT_VALUE_FIELD; static final String KEY_VALUE_TAG_PREFIX; static final String KEY_VALUE_TIMESTAMPED_ANNOTATION_PREFIX; }
@UseDataProvider("escapeJsonScenarioDataProvider") @Test public void unescapeJson_unescapes_characters_as_expected(EscapeJsonScenario scenario) throws IOException { Map<String, String> jacksonDeserialized = objectMapper.readValue( "{\"foo\":\"" + scenario.expectedEscaped + "\"}", new TypeReference<Map<String, String>>(){} ); String jacksonUnescaped = jacksonDeserialized.get("foo"); String unescaped = SpanParser.unescapeJson(scenario.expectedEscaped); assertThat(unescaped).isEqualTo(jacksonUnescaped); assertThat(unescaped).isEqualTo(scenario.strToEscape); }
@Test public void unescapeJson_returns_null_if_passed_null() { assertThat(SpanParser.unescapeJson(null)).isNull(); }
@Test public void unescapeJson_returns_same_instance_if_no_backspace_chars_exist() { String orig = UUID.randomUUID().toString(); assertThat(SpanParser.unescapeJson(orig)).isSameAs(orig); }