Search in sources :

Example 21 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject 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;
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) HttpException(org.sonarqube.ws.client.HttpException) MessageException(org.sonar.api.utils.MessageException) JsonParser(com.google.gson.JsonParser)

Example 22 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project sonarqube by SonarSource.

the class QualityGateDetailsData method toJson.

private static JsonObject toJson(EvaluatedCondition evaluatedCondition) {
    Condition condition = evaluatedCondition.getCondition();
    JsonObject result = new JsonObject();
    result.addProperty("metric", condition.getMetric().getKey());
    result.addProperty("op", condition.getOperator().getDbValue());
    if (condition.hasPeriod()) {
        result.addProperty("period", 1);
    }
    if (condition.getWarningThreshold() != null) {
        result.addProperty("warning", condition.getWarningThreshold());
    }
    if (condition.getErrorThreshold() != null) {
        result.addProperty("error", condition.getErrorThreshold());
    }
    result.addProperty("actual", evaluatedCondition.getActualValue());
    result.addProperty(FIELD_LEVEL, evaluatedCondition.getLevel().name());
    return result;
}
Also used : Condition(org.sonar.server.computation.task.projectanalysis.qualitygate.Condition) JsonObject(com.google.gson.JsonObject)

Example 23 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project sonarqube by SonarSource.

the class QualityGateDetailsData method toJson.

public String toJson() {
    JsonObject details = new JsonObject();
    details.addProperty(FIELD_LEVEL, level.toString());
    JsonArray conditionResults = new JsonArray();
    for (EvaluatedCondition condition : this.conditions) {
        conditionResults.add(toJson(condition));
    }
    details.add("conditions", conditionResults);
    return details.toString();
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject)

Example 24 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project che by eclipse.

the class JsonRpcEntityQualifier method qualify.

public JsonRpcEntityType qualify(String message) {
    checkNotNull(message, "Message must not be null");
    checkArgument(!message.isEmpty(), "Message must not be empty");
    LOG.debug("Qualifying message: " + message);
    JsonObject jsonObject = jsonParser.parse(message).getAsJsonObject();
    LOG.debug("Json keys: " + jsonObject.entrySet().stream().map(Map.Entry::getKey).collect(Collectors.toSet()));
    if (jsonObject.has("method")) {
        LOG.debug("Qualified to request");
        return JsonRpcEntityType.REQUEST;
    } else if (jsonObject.has("error") != jsonObject.has("result")) {
        LOG.debug("Qualified to response");
        return JsonRpcEntityType.RESPONSE;
    } else {
        LOG.debug("Qualified to undefined");
        return JsonRpcEntityType.UNDEFINED;
    }
}
Also used : JsonObject(com.google.gson.JsonObject) Map(java.util.Map)

Example 25 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project che by eclipse.

the class JsonRpcError method toJsonObject.

public JsonObject toJsonObject() {
    JsonObject error = new JsonObject();
    error.addProperty("code", code);
    error.addProperty("message", message);
    return error;
}
Also used : JsonObject(com.google.gson.JsonObject)

Aggregations

JsonObject (com.google.gson.JsonObject)5111 JsonArray (com.google.gson.JsonArray)1162 JsonElement (com.google.gson.JsonElement)1084 JsonParser (com.google.gson.JsonParser)710 Test (org.junit.Test)491 IOException (java.io.IOException)471 JsonPrimitive (com.google.gson.JsonPrimitive)387 ArrayList (java.util.ArrayList)376 Gson (com.google.gson.Gson)369 HashMap (java.util.HashMap)324 Map (java.util.Map)269 Test (org.testng.annotations.Test)208 Test (org.junit.jupiter.api.Test)201 File (java.io.File)146 List (java.util.List)142 InputStreamReader (java.io.InputStreamReader)135 JsonParseException (com.google.gson.JsonParseException)121 GsonBuilder (com.google.gson.GsonBuilder)93 JsonSyntaxException (com.google.gson.JsonSyntaxException)88 Nonnull (javax.annotation.Nonnull)87