Example usage for com.google.gson JsonArray add

List of usage examples for com.google.gson JsonArray add

Introduction

In this page you can find the example usage for com.google.gson JsonArray add.

Prototype

public void add(JsonElement element) 

Source Link

Document

Adds the specified element to self.

Usage

From source file:com.cloudant.client.internal.views.ViewMultipleRequester.java

License:Open Source License

public List<ViewResponse<K, V>> getViewResponses() throws IOException {
    //build the queries array of data to POST
    JsonArray queries = new JsonArray();
    ViewQueryParameters<K, V> viewQueryParameters = null;
    for (ViewQueryParameters<K, V> params : requestParameters) {
        if (viewQueryParameters == null) {
            viewQueryParameters = params;
        }/*from w ww  .j av a2s .  c o m*/
        queries.add(params.asJson());
    }
    JsonObject queryJson = new JsonObject();
    queryJson.add("queries", queries);
    //construct and execute the POST request
    HttpPost post = new HttpPost(viewQueryParameters.getViewURIBuilder().buildEncoded());
    StringEntity entity = new StringEntity(queryJson.toString(), "UTF-8");
    entity.setContentType("application/json");
    post.setEntity(entity);
    JsonObject jsonResponse = ViewRequester.executeRequestWithResponseAsJson(viewQueryParameters, post);
    //loop the returned array creating the ViewResponse objects
    List<ViewResponse<K, V>> responses = new ArrayList<ViewResponse<K, V>>();
    JsonArray jsonResponses = jsonResponse.getAsJsonArray("results");
    if (jsonResponses != null) {
        int index = 0;
        for (ViewQueryParameters<K, V> params : requestParameters) {
            JsonObject response = jsonResponses.get(index).getAsJsonObject();
            responses.add(new ViewResponseImpl<K, V>(params, response));
            index++;
        }
        return responses;
    } else {
        return Collections.emptyList();
    }
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonMethods(MethodBinding[] methods) {
    if (methods == null)
        return JsonNull.INSTANCE;
    JsonArray jsonElements = new JsonArray();
    for (MethodBinding method : methods) {
        jsonElements.add(toJsonMethod(method));
    }//from ww w  .jav a 2  s  . co  m
    return jsonElements;
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonParameterAnnotations(MethodBinding method) {
    AnnotationBinding[][] parameterAnnotations = method.getParameterAnnotations();
    if (parameterAnnotations == null)
        return JsonNull.INSTANCE;
    JsonArray array = new JsonArray();
    for (AnnotationBinding[] parameterAnnotation : parameterAnnotations) {
        array.add(toJsonAnnotations(parameterAnnotation));
    }/* w ww.  ja v  a 2  s  .  co  m*/
    return array;
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonExceptionTypeNames(ReferenceBinding[] thrownExceptions) {
    if (thrownExceptions == null)
        return JsonNull.INSTANCE;
    JsonArray array = new JsonArray();
    for (ReferenceBinding exception : thrownExceptions) {
        array.add(new JsonPrimitive(new String(exception.constantPoolName())));
    }/*w w  w .  j a v a2s.com*/
    return array;
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonDefaultValue(Object defaultValue) {
    if (defaultValue == null)
        return JsonNull.INSTANCE;
    JsonObject object = new JsonObject();
    if (defaultValue instanceof Constant) {
        object.add("constant", BinaryTypeConvector.toJsonConstant((Constant) defaultValue));
    } else if (defaultValue instanceof TypeBinding) {
        object.addProperty("class", new String(((TypeBinding) defaultValue).constantPoolName()));
    } else if (defaultValue instanceof AnnotationBinding) {
        object.add("annotation", toJsonAnnotation((AnnotationBinding) defaultValue));
    } else if (defaultValue instanceof FieldBinding) {
        FieldBinding signature = (FieldBinding) defaultValue;
        JsonObject enumSignature = new JsonObject();
        enumSignature.addProperty("typeName", new String(signature.type.signature()));
        enumSignature.addProperty("constantName", new String(signature.name));
        object.add("enum", enumSignature);
    } else if (defaultValue instanceof Object[]) {
        JsonArray array = new JsonArray();
        for (Object o : (Object[]) defaultValue) {
            array.add(toJsonDefaultValue(o));
        }/*from  www.  j  a  v  a 2s.  c om*/
        object.add("array", array);
    }

    return object;
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonParametersName(AbstractMethodDeclaration parameters) {
    if (parameters == null || parameters.arguments == null || parameters.arguments.length == 0)
        return JsonNull.INSTANCE;
    JsonArray array = new JsonArray();

    for (Argument parameter : parameters.arguments) {
        array.add(new JsonPrimitive(new String(parameter.binding.name)));
    }/*from   w  w  w.  j a  va2s  .  c  o  m*/
    return array;

}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonMemberTypes(ReferenceBinding[] memberTypes) {
    if (memberTypes == null || memberTypes.length == 0)
        return null;
    JsonArray array = new JsonArray();
    for (ReferenceBinding type : memberTypes) {
        array.add(toJsonMemberType(type));
    }//  ww  w  . j  a  v  a  2 s  .  c o m
    return array;

}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonInterfaces(ReferenceBinding[] interfaces) {
    if (interfaces == null)
        return JsonNull.INSTANCE;
    JsonArray array = new JsonArray();
    for (ReferenceBinding anInterface : interfaces) {
        array.add(new JsonPrimitive(new String(anInterface.constantPoolName())));
    }/*www .  j  a v a2s.  c o m*/
    return array;
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonFields(FieldBinding[] fields) {
    if (fields == null || fields.length == 0)
        return JsonNull.INSTANCE;
    JsonArray array = new JsonArray();
    for (FieldBinding field : fields) {
        array.add(toJsonField(field));
    }//from ww  w  .j  av  a  2  s . c o m
    return array;
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonAnnotations(AnnotationBinding[] annotations) {
    if (annotations == null)
        return JsonNull.INSTANCE;
    JsonArray array = new JsonArray();
    for (AnnotationBinding annotation : annotations) {
        array.add(toJsonAnnotation(annotation));
    }/*from  w  w  w. ja  va  2s  .co  m*/
    return array;
}