Search in sources :

Example 1 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project weixin-java-tools by chanjarster.

the class WxCpServiceImpl method userDelete.

@Override
public void userDelete(String[] userids) throws WxErrorException {
    String url = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete";
    JsonObject jsonObject = new JsonObject();
    JsonArray jsonArray = new JsonArray();
    for (int i = 0; i < userids.length; i++) {
        jsonArray.add(new JsonPrimitive(userids[i]));
    }
    jsonObject.add("useridlist", jsonArray);
    post(url, jsonObject.toString());
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject)

Example 2 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project weixin-java-tools by chanjarster.

the class WxCpServiceImpl method tagAddUsers.

@Override
public void tagAddUsers(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException {
    String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers";
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("tagid", tagId);
    if (userIds != null) {
        JsonArray jsonArray = new JsonArray();
        for (String userId : userIds) {
            jsonArray.add(new JsonPrimitive(userId));
        }
        jsonObject.add("userlist", jsonArray);
    }
    if (partyIds != null) {
        JsonArray jsonArray = new JsonArray();
        for (String userId : partyIds) {
            jsonArray.add(new JsonPrimitive(userId));
        }
        jsonObject.add("partylist", jsonArray);
    }
    post(url, jsonObject.toString());
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject)

Example 3 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project che by eclipse.

the class JsonRpcResultTest method shouldGetAsListOfStringWhenParsingStringWithResultAsString.

@Test
public void shouldGetAsListOfStringWhenParsingStringWithResultAsString() throws Exception {
    String expected = "a";
    JsonPrimitive primitive = new JsonPrimitive(expected);
    JsonArray array = new JsonArray();
    array.add(primitive);
    JsonRpcResult jsonRpcResult = new JsonRpcResult(array.toString(), jsonParser);
    List<String> actual = jsonRpcResult.getAsListOf(String.class);
    assertEquals(expected, actual.iterator().next());
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) Test(org.testng.annotations.Test)

Example 4 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project che by eclipse.

the class JsonRpcResultTest method shouldToJsonValueWhenPassingParametersWithResultAsASingleString.

@Test
public void shouldToJsonValueWhenPassingParametersWithResultAsASingleString() throws Exception {
    String value = "a";
    JsonPrimitive expected = new JsonPrimitive(value);
    JsonRpcResult jsonRpcResult = new JsonRpcResult(value, jsonParser);
    JsonElement actual = jsonRpcResult.toJsonElement();
    assertEquals(expected, actual);
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) Test(org.testng.annotations.Test)

Example 5 with JsonPrimitive

use of com.google.gson.JsonPrimitive in project che by eclipse.

the class JsonRpcParamsTest method shouldToJsonForCreatedListDoubleParams.

@Test
public void shouldToJsonForCreatedListDoubleParams() throws Exception {
    double value = 0D;
    List<Double> list = singletonList(value);
    JsonArray expected = new JsonArray();
    expected.add(new JsonPrimitive(value));
    JsonRpcParams jsonRpcParams = new JsonRpcParams(list, jsonParser);
    JsonElement actual = jsonRpcParams.toJsonElement();
    assertEquals(expected, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) Test(org.testng.annotations.Test)

Aggregations

JsonPrimitive (com.google.gson.JsonPrimitive)168 JsonArray (com.google.gson.JsonArray)103 JsonObject (com.google.gson.JsonObject)78 Test (org.testng.annotations.Test)56 JsonElement (com.google.gson.JsonElement)47 Test (org.junit.Test)12 Map (java.util.Map)9 Matchers.anyString (org.mockito.Matchers.anyString)8 JsonProcessorInjectionMap (com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap)7 Gson (com.google.gson.Gson)5 JsonParser (com.google.gson.JsonParser)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 GsonBuilder (com.google.gson.GsonBuilder)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Matcher (java.util.regex.Matcher)3 LobWrapper (angularBeans.io.LobWrapper)2 DatasetCreationSpec (co.cask.cdap.internal.dataset.DatasetCreationSpec)2 IRenderState (com.builtbroken.mc.client.json.imp.IRenderState)2