SpanParser { public static Span fromJSON(String json) { try { JsonDeserializationResult mainResult = deserializeJsonObject(json, 0); Map<String, String> mainMap = mainResult.levelOneKeyValuePairs; JsonDeserializationResult tagsResult = mainResult.subObjects.get(TAGS_FIELD); Map<String, String> tagsMap = (tagsResult == null) ? null : tagsResult.levelOneKeyValuePairs; List<TimestampedAnnotation> annotationsList = convertToTimestampedAnnotationsList( mainResult.arrays.get(ANNOTATIONS_LIST_FIELD) ); return fromKeyValueMap(mainMap, tagsMap, annotationsList); } catch (Exception e) { logger.error("Error extracting Span from JSON. Defaulting to null. bad_span_json={}", json, e); return null; } } 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("badJsonScenarioDataProvider") @Test public void fromJson_should_return_null_for_garbage_input(BadJsonScenario scenario) { String garbageInput = scenario.generateBadJson( Span.newBuilder("foo", SpanPurpose.CLIENT) .withTag("footag", "bar") .withTimestampedAnnotations(Arrays.asList( TimestampedAnnotation.forCurrentTime("fooAnnotation"), TimestampedAnnotation.forCurrentTime("barAnnotation") )) .build() ); Span spanFromJson = SpanParser.fromJSON(garbageInput); assertThat(spanFromJson).isNull(); }