Search in sources :

Example 51 with Annotation

use of org.sbolstandard.core2.Annotation in project zipkin by openzipkin.

the class JsonSerializers method parseSpan.

static Span parseSpan(JsonParser parser) throws IOException {
    if (!parser.isExpectedStartObjectToken()) {
        throw new IllegalArgumentException("Not a valid JSON object, start token: " + parser.currentToken());
    }
    Span.Builder result = Span.newBuilder();
    JsonToken value;
    while ((value = parser.nextValue()) != JsonToken.END_OBJECT) {
        if (value == null) {
            throw new IOException("End of input while parsing object.");
        }
        if (value == JsonToken.VALUE_NULL) {
            continue;
        }
        switch(parser.currentName()) {
            case "traceId":
                result.traceId(parser.getText());
                break;
            case "parentId":
                result.parentId(parser.getText());
                break;
            case "id":
                result.id(parser.getText());
                break;
            case "kind":
                result.kind(Span.Kind.valueOf(parser.getText()));
                break;
            case "name":
                result.name(parser.getText());
                break;
            case "timestamp":
                result.timestamp(parser.getLongValue());
                break;
            case "duration":
                result.duration(parser.getLongValue());
                break;
            case "localEndpoint":
                result.localEndpoint(parseEndpoint(parser));
                break;
            case "remoteEndpoint":
                result.remoteEndpoint(parseEndpoint(parser));
                break;
            case "annotations":
                if (value != JsonToken.START_ARRAY) {
                    throw new IOException("Invalid span, expecting annotations array start, got: " + value);
                }
                while (parser.nextToken() != JsonToken.END_ARRAY) {
                    Annotation a = parseAnnotation(parser);
                    result.addAnnotation(a.timestamp(), a.value());
                }
                break;
            case "tags":
                if (value != JsonToken.START_OBJECT) {
                    throw new IOException("Invalid span, expecting tags object, got: " + value);
                }
                while (parser.nextValue() != JsonToken.END_OBJECT) {
                    result.putTag(parser.currentName(), parser.getValueAsString());
                }
                break;
            case "debug":
                result.debug(parser.getBooleanValue());
                break;
            case "shared":
                result.shared(parser.getBooleanValue());
                break;
            default:
        }
    }
    return result.build();
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException) Span(zipkin2.Span) Annotation(zipkin2.Annotation)

Aggregations

URI (java.net.URI)33 QName (javax.xml.namespace.QName)33 ArrayList (java.util.ArrayList)31 HashSet (java.util.HashSet)31 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)31 Literal (org.sbolstandard.core.datatree.Literal)30 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)30 IdentifiableDocument (org.sbolstandard.core.datatree.IdentifiableDocument)17 NestedDocument (org.sbolstandard.core.datatree.NestedDocument)13 Annotation (zipkin2.Annotation)11 Map (java.util.Map)8 ComponentDefinition (org.sbolstandard.core2.ComponentDefinition)7 SBOLDocument (org.sbolstandard.core2.SBOLDocument)5 Endpoint (zipkin2.Endpoint)5 Activity (org.sbolstandard.core2.Activity)4 LinkedHashMap (java.util.LinkedHashMap)3 Test (org.junit.Test)3 Annotation (org.sbolstandard.core2.Annotation)3 Span (zipkin2.Span)3 JsonToken (com.fasterxml.jackson.core.JsonToken)2