use of com.google.gson.stream.JsonReader in project intellij-community by JetBrains.
the class DiffHttpService method execute.
@Override
@Nullable
public String execute(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) throws IOException {
final List<DiffContent> contents = new ArrayList<>();
final List<String> titles = new ArrayList<>();
boolean focused = true;
String windowTitle = null;
JsonReader reader = createJsonReader(request);
if (reader.hasNext()) {
String fileType = null;
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
if (name.equals("fileType")) {
fileType = reader.nextString();
} else if (name.equals("focused")) {
focused = reader.nextBoolean();
} else if (name.equals("windowTitle")) {
windowTitle = StringUtil.nullize(reader.nextString(), true);
} else if (name.equals("contents")) {
String error = readContent(reader, contents, titles, fileType);
if (error != null) {
return error;
}
} else {
reader.skipValue();
}
}
reader.endObject();
}
if (contents.isEmpty()) {
return "Empty request";
}
Project project = getLastFocusedOrOpenedProject();
if (project == null) {
// Argument for @NotNull parameter 'project' of com/intellij/openapi/components/ServiceManager.getService must not be null
project = ProjectManager.getInstance().getDefaultProject();
}
final boolean finalFocused = focused;
final String finalWindowTitle = windowTitle;
final Project finalProject = project;
ApplicationManager.getApplication().invokeLater(() -> {
if (finalFocused) {
ProjectUtil.focusProjectWindow(finalProject, true);
}
DiffManager.getInstance().showDiff(finalProject, new SimpleDiffRequest(StringUtil.notNullize(finalWindowTitle, "Diff Service"), contents, titles));
}, project.getDisposed());
sendOk(request, context);
return null;
}
use of com.google.gson.stream.JsonReader in project cloudstack by apache.
the class Request method getCommands.
public Command[] getCommands() {
if (_cmds == null) {
try {
StringReader reader = new StringReader(_content);
JsonReader jsonReader = new JsonReader(reader);
jsonReader.setLenient(true);
_cmds = s_gson.fromJson(jsonReader, (Type) Command[].class);
} catch (RuntimeException e) {
s_logger.error("Caught problem with " + _content, e);
throw e;
}
}
return _cmds;
}
use of com.google.gson.stream.JsonReader in project gce2retrofit by chiuki.
the class Generator method generate.
public static void generate(Reader discoveryReader, WriterFactory writerFactory, Map<String, String> classMap, EnumSet<MethodType> methodTypes, Map<String, String> packageMap) throws IOException, URISyntaxException {
JsonReader jsonReader = new JsonReader(discoveryReader);
Discovery discovery = gson.fromJson(jsonReader, Discovery.class);
String packageName = StringUtil.getPackageName(discovery.baseUrl);
if (packageName == null || packageName.isEmpty()) {
packageName = StringUtil.getPackageName(discovery.rootUrl);
}
String modelPackageName = packageName + ".model";
for (Entry<String, JsonElement> entry : discovery.schemas.entrySet()) {
generateModel(writerFactory, modelPackageName, entry.getValue().getAsJsonObject(), classMap, packageMap);
}
if (discovery.resources != null) {
generateInterfaceFromResources(writerFactory, packageName, "", discovery.resources, methodTypes, packageMap);
}
if (discovery.name != null && discovery.methods != null) {
generateInterface(writerFactory, packageName, discovery.name, discovery.methods, methodTypes, packageMap);
}
}
use of com.google.gson.stream.JsonReader in project cdap by caskdata.
the class JsonStructuredRecordDatumReader method decodeMap.
@Override
protected Map<?, ?> decodeMap(Decoder decoder, Schema keySchema, Schema valueSchema) throws IOException {
if (!keySchema.isCompatible(Schema.of(Schema.Type.STRING))) {
throw new IOException("Complex key type in maps are not supported: " + keySchema);
}
Map<Object, Object> result = new HashMap<>();
JsonReader jsonReader = getJsonReader(decoder);
jsonReader.beginObject();
while (jsonReader.peek() != JsonToken.END_OBJECT) {
Object key = convertKey(jsonReader.nextName(), keySchema.getType());
result.put(key, decode(decoder, valueSchema));
}
jsonReader.endObject();
return result;
}
use of com.google.gson.stream.JsonReader in project cdap by caskdata.
the class JsonStructuredRecordDatumReader method decodeUnion.
@Override
protected Object decodeUnion(Decoder decoder, Schema unionSchema) throws IOException {
JsonReader jsonReader = getJsonReader(decoder);
JsonToken token = jsonReader.peek();
// Based on the token to guess the schema
for (Schema schema : unionSchema.getUnionSchemas()) {
if (SCHEMA_TO_JSON_TYPE.get(schema.getType()) == token) {
return decode(decoder, schema);
}
}
throw new IOException(String.format("No matching schema found for union type: %s for token: %s", unionSchema, token));
}
Aggregations