use of com.google.gson.JsonElement in project remusic by aa112901.
the class HttpUtil method getResposeJsonObject.
public static JsonObject getResposeJsonObject(String action1) {
try {
mOkHttpClient.setConnectTimeout(3000, TimeUnit.MINUTES);
mOkHttpClient.setReadTimeout(3000, TimeUnit.MINUTES);
Request request = new Request.Builder().url(action1).build();
Response response = mOkHttpClient.newCall(request).execute();
if (response.isSuccessful()) {
String c = response.body().string();
// FileOutputStream fileOutputStream = new FileOutputStream("/sdcard/" + System.currentTimeMillis() + ".txt");
// fileOutputStream.write(c.getBytes());
// fileOutputStream.close();
JsonParser parser = new JsonParser();
JsonElement el = parser.parse(c);
return el.getAsJsonObject();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of com.google.gson.JsonElement in project sonarqube by SonarSource.
the class ScannerWsClient method tryParseAsJsonError.
public static String tryParseAsJsonError(String responseContent) {
try {
JsonParser parser = new JsonParser();
JsonObject obj = parser.parse(responseContent).getAsJsonObject();
JsonArray errors = obj.getAsJsonArray("errors");
List<String> errorMessages = new ArrayList<>();
for (JsonElement e : errors) {
errorMessages.add(e.getAsJsonObject().get("msg").getAsString());
}
return Joiner.on(", ").join(errorMessages);
} catch (Exception e) {
return responseContent;
}
}
use of com.google.gson.JsonElement in project sonarqube by SonarSource.
the class QualityGateDetailsFormatter method formatConditionPeriod.
private static void formatConditionPeriod(ProjectStatusWsResponse.Condition.Builder conditionBuilder, JsonObject jsonCondition) {
JsonElement periodIndex = jsonCondition.get("period");
if (periodIndex == null) {
return;
}
conditionBuilder.setPeriodIndex(periodIndex.getAsInt());
}
use of com.google.gson.JsonElement in project ninja by ninjaframework.
the class ApiControllerDocTest method getGsonWithLongToDateParsing.
private Gson getGsonWithLongToDateParsing() {
// Creates the json object which will manage the information received
GsonBuilder builder = new GsonBuilder();
// Register an adapter to manage the date types as long values
builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
@Override
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return new Date(json.getAsJsonPrimitive().getAsLong());
}
});
Gson gson = builder.create();
return gson;
}
use of com.google.gson.JsonElement in project ninja by ninjaframework.
the class ApiControllerDocTesterTest method getGsonWithLongToDateParsing.
private Gson getGsonWithLongToDateParsing() {
// Creates the json object which will manage the information received
GsonBuilder builder = new GsonBuilder();
// Register an adapter to manage the date types as long values
builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
@Override
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return new Date(json.getAsJsonPrimitive().getAsLong());
}
});
Gson gson = builder.create();
return gson;
}
Aggregations