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));
}
}
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;
}
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));
}
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;
}
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();
}
}
Aggregations