Search in sources :

Example 11 with JsonToken

use of com.google.gson.stream.JsonToken in project airavata by apache.

the class JsonWorkflowParser method readWorkflowOutputs.

private void readWorkflowOutputs(JsonReader jsonReader) throws IOException, ParserException {
    JsonToken peek = jsonReader.peek();
    OutputNode outputNode;
    NodeModel nodeModel;
    ComponentStatus status;
    String name;
    if (peek == JsonToken.NULL) {
        throw new ParserException("Error! workflow outputs can't be null");
    } else if (peek == JsonToken.BEGIN_ARRAY) {
        jsonReader.beginArray();
        while (jsonReader.hasNext()) {
            jsonReader.beginObject();
            nodeModel = new NodeModel();
            status = new ComponentStatus();
            status.setState(ComponentState.CREATED);
            status.setReason("Created");
            nodeModel.setStatus(status);
            outputNode = new OutputNodeImpl(nodeModel);
            while (jsonReader.hasNext()) {
                name = jsonReader.nextName();
                if (name.equals(NAME)) {
                    nodeModel.setName(jsonReader.nextString());
                } else if (name.equals(ID)) {
                    nodeModel.setNodeId(jsonReader.nextString());
                } else if (name.equals(DATATYPE)) {
                    jsonReader.skipValue();
                } else if (name.equals(DESCRIPTION)) {
                    nodeModel.setDescription(jsonReader.nextString());
                } else if (name.equals(POSITION)) {
                    readPosition(jsonReader);
                } else if (name.equals(NODE_ID)) {
                    jsonReader.skipValue();
                // nodeModel.setNodeId(jsonReader.nextString());
                } else if (name.equals(DEFAULT_VALUE)) {
                    jsonReader.skipValue();
                } else {
                    jsonReader.skipValue();
                }
            }
            jsonReader.endObject();
            outputs.add(outputNode);
        }
        jsonReader.endArray();
    } else {
        throw new ParserException("Error! Unsupported value for Workflow Outputs, exptected " + getTokenString(JsonToken.BEGIN_OBJECT) + " but found" + getTokenString(peek));
    }
}
Also used : OutputNode(org.apache.airavata.workflow.core.dag.nodes.OutputNode) NodeModel(org.apache.airavata.model.NodeModel) ComponentStatus(org.apache.airavata.model.ComponentStatus) JsonToken(com.google.gson.stream.JsonToken) OutputNodeImpl(org.apache.airavata.workflow.core.dag.nodes.OutputNodeImpl)

Example 12 with JsonToken

use of com.google.gson.stream.JsonToken in project go-lang-idea-plugin by go-lang-plugin-org.

the class JsonReaderEx method subReader.

@Nullable
public JsonReaderEx subReader() {
    JsonToken nextToken = peek();
    switch(nextToken) {
        case BEGIN_ARRAY:
        case BEGIN_OBJECT:
        case STRING:
        case NUMBER:
        case BOOLEAN:
            break;
        case NULL:
            // just return null
            return null;
        default:
            throw createParseError("Cannot create sub reader, next token " + nextToken + " is not value");
    }
    JsonReaderEx subReader = new JsonReaderEx(in, position, Arrays.copyOf(stack, stack.length));
    subReader.stackSize = stackSize;
    subReader.peeked = peeked;
    subReader.peekedLong = peekedLong;
    subReader.peekedNumberLength = peekedNumberLength;
    subReader.peekedString = peekedString;
    return subReader;
}
Also used : JsonToken(com.google.gson.stream.JsonToken) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with JsonToken

use of com.google.gson.stream.JsonToken in project go-lang-idea-plugin by go-lang-plugin-org.

the class JsonReaderEx method asGson.

@NotNull
public JsonReader asGson() {
    JsonToken nextToken = peek();
    switch(nextToken) {
        case BEGIN_ARRAY:
        case BEGIN_OBJECT:
        case STRING:
        case NUMBER:
        case BOOLEAN:
            break;
        default:
            throw createParseError("Cannot create sub reader, next token " + nextToken + " is not value");
    }
    CharSequence sequence = position > 0 ? in.subSequence(position - 1, in.length()) : in;
    return new JsonReader(new CharSequenceReader(sequence));
}
Also used : CharSequenceReader(com.intellij.util.text.CharSequenceReader) JsonReader(com.google.gson.stream.JsonReader) JsonToken(com.google.gson.stream.JsonToken) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with JsonToken

use of com.google.gson.stream.JsonToken in project maple-ir by LLVM-but-worse.

the class JsonTreeReader method nextInt.

@Override
public int nextInt() throws IOException {
    JsonToken token = peek();
    if (token != JsonToken.NUMBER && token != JsonToken.STRING) {
        throw new IllegalStateException("Expected " + JsonToken.NUMBER + " but was " + token);
    }
    int result = ((JsonPrimitive) peekStack()).getAsInt();
    popStack();
    return result;
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonToken(com.google.gson.stream.JsonToken)

Example 15 with JsonToken

use of com.google.gson.stream.JsonToken in project maple-ir by LLVM-but-worse.

the class ObjectTypeAdapter method read.

@Override
public Object read(JsonReader in) throws IOException {
    JsonToken token = in.peek();
    switch(token) {
        case BEGIN_ARRAY:
            List<Object> list = new ArrayList<Object>();
            in.beginArray();
            while (in.hasNext()) {
                list.add(read(in));
            }
            in.endArray();
            return list;
        case BEGIN_OBJECT:
            Map<String, Object> map = new LinkedTreeMap<String, Object>();
            in.beginObject();
            while (in.hasNext()) {
                map.put(in.nextName(), read(in));
            }
            in.endObject();
            return map;
        case STRING:
            return in.nextString();
        case NUMBER:
            return in.nextDouble();
        case BOOLEAN:
            return in.nextBoolean();
        case NULL:
            in.nextNull();
            return null;
        default:
            throw new IllegalStateException();
    }
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) ArrayList(java.util.ArrayList) JsonToken(com.google.gson.stream.JsonToken)

Aggregations

JsonToken (com.google.gson.stream.JsonToken)26 JsonReader (com.google.gson.stream.JsonReader)9 IOException (java.io.IOException)6 List (java.util.List)4 JsonPrimitive (com.google.gson.JsonPrimitive)3 InputStreamReader (java.io.InputStreamReader)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 BufferedReader (java.io.BufferedReader)2 PortModel (org.apache.airavata.model.PortModel)2 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)2 ListWaitingObject (org.bimserver.shared.ListWaitingObject)2 WaitingList (org.bimserver.shared.WaitingList)2 AbstractEList (org.eclipse.emf.common.util.AbstractEList)2 EList (org.eclipse.emf.common.util.EList)2 EObject (org.eclipse.emf.ecore.EObject)2 EReference (org.eclipse.emf.ecore.EReference)2 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2 ParsingException (org.eclipse.smarthome.automation.parser.ParsingException)2 ParsingNestedException (org.eclipse.smarthome.automation.parser.ParsingNestedException)2