use of com.google.gson.GsonBuilder in project Geolosys by oitsjustjose.
the class Geolosys method getOresConfig.
@Nonnull
private ConfigOres getOresConfig(File configDir) {
try {
FileReader fr = new FileReader(configDir.getAbsolutePath() + "/geolosys_ores.json".replace("/", File.separator));
BufferedReader br = new BufferedReader(fr);
String line;
StringBuilder json = new StringBuilder();
try {
while ((line = br.readLine()) != null) {
json.append(line);
}
Gson gson = new GsonBuilder().setPrettyPrinting().create();
ConfigOres ret = gson.fromJson(json.toString(), ConfigOres.class);
ret.validate(configDir);
return ret;
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
ConfigOres props = new ConfigOres();
props.populateConfigs();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(props);
try {
FileWriter fw = new FileWriter(configDir.getAbsolutePath() + "/geolosys_ores.json".replace("/", File.separator));
fw.write(json);
fw.close();
return props;
} catch (IOException ex) {
ex.printStackTrace();
}
}
return getOresConfig(configDir);
}
use of com.google.gson.GsonBuilder in project linuxtools by eclipse.
the class OSIORestPatchUpdateTask method addHttpRequestEntities.
@SuppressWarnings("deprecation")
@Override
protected void addHttpRequestEntities(HttpRequestBase request) throws OSIORestException {
super.addHttpRequestEntities(request);
try {
Gson gson = new GsonBuilder().registerTypeAdapter(OldAttributes.class, new TaskAttributeTypeAdapter(getClient().getLocation())).create();
StringEntity requestEntity = new StringEntity(gson.toJson(oldAttributes));
((HttpPatch) request).setEntity(requestEntity);
} catch (UnsupportedEncodingException e) {
Throwables.propagate(new CoreException(// $NON-NLS-1$
new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, "Can not build HttpRequest", e)));
}
}
use of com.google.gson.GsonBuilder in project linuxtools by eclipse.
the class OSIORestPostNewCommentTask method addHttpRequestEntities.
@SuppressWarnings("deprecation")
@Override
protected void addHttpRequestEntities(HttpRequestBase request) throws OSIORestException {
super.addHttpRequestEntities(request);
try {
Gson gson = new GsonBuilder().registerTypeAdapter(OldAttributes.class, new TaskAttributeTypeAdapter(getClient().getLocation())).create();
StringEntity requestEntity = new StringEntity(gson.toJson(oldAttributes));
((HttpPost) request).setEntity(requestEntity);
} catch (UnsupportedEncodingException e) {
Throwables.propagate(new CoreException(// $NON-NLS-1$
new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, "Can not build HttpRequest", e)));
}
}
use of com.google.gson.GsonBuilder in project linuxtools by eclipse.
the class OSIORestPostNewLabelTask method addHttpRequestEntities.
@SuppressWarnings("deprecation")
@Override
protected void addHttpRequestEntities(HttpRequestBase request) throws OSIORestException {
super.addHttpRequestEntities(request);
try {
Gson gson = new GsonBuilder().registerTypeAdapter(String.class, new TaskAttributeTypeAdapter()).create();
StringEntity requestEntity = new StringEntity(gson.toJson(newLabel));
((HttpPost) request).setEntity(requestEntity);
} catch (UnsupportedEncodingException e) {
Throwables.propagate(new CoreException(// $NON-NLS-1$
new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, "Can not build HttpRequest", e)));
}
}
use of com.google.gson.GsonBuilder in project linuxtools by eclipse.
the class OSIORestPostNewTask method addHttpRequestEntities.
@SuppressWarnings("deprecation")
@Override
protected void addHttpRequestEntities(HttpRequestBase request) throws OSIORestException {
super.addHttpRequestEntities(request);
try {
Gson gson = new GsonBuilder().registerTypeAdapter(TaskData.class, new TaskAttributeTypeAdapter(getClient().getLocation())).create();
StringEntity requestEntity = new StringEntity(gson.toJson(taskData));
((HttpPost) request).setEntity(requestEntity);
} catch (UnsupportedEncodingException e) {
Throwables.propagate(new CoreException(// $NON-NLS-1$
new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, "Can not build HttpRequest", e)));
}
}
Aggregations