Search in sources :

Example 56 with JsonReader

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

the class WxCpServiceImpl method departCreate.

public Integer departCreate(WxCpDepart depart) throws WxErrorException {
    String url = "https://qyapi.weixin.qq.com/cgi-bin/department/create";
    String responseContent = execute(new SimplePostRequestExecutor(), url, depart.toJson());
    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
    return GsonHelper.getAsInteger(tmpJsonElement.getAsJsonObject().get("id"));
}
Also used : JsonElement(com.google.gson.JsonElement) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader) SimplePostRequestExecutor(me.chanjar.weixin.common.util.http.SimplePostRequestExecutor)

Example 57 with JsonReader

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

the class WxCpServiceImpl method oauth2getUserInfo.

@Override
public String[] oauth2getUserInfo(String agentId, String code) throws WxErrorException {
    String url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?" + "code=" + code + "&agendid=" + agentId;
    String responseText = get(url, null);
    JsonElement je = Streams.parse(new JsonReader(new StringReader(responseText)));
    JsonObject jo = je.getAsJsonObject();
    return new String[] { GsonHelper.getString(jo, "UserId"), GsonHelper.getString(jo, "DeviceId") };
}
Also used : JsonElement(com.google.gson.JsonElement) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader) JsonObject(com.google.gson.JsonObject)

Example 58 with JsonReader

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

the class WxMpServiceImpl method getCallbackIP.

@Override
public String[] getCallbackIP() throws WxErrorException {
    String url = "https://api.weixin.qq.com/cgi-bin/getcallbackip";
    String responseContent = get(url, null);
    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
    JsonArray ipList = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
    String[] ipArray = new String[ipList.size()];
    for (int i = 0; i < ipList.size(); i++) {
        ipArray[i] = ipList.get(i).getAsString();
    }
    return ipArray;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader)

Example 59 with JsonReader

use of com.google.gson.stream.JsonReader in project cryptomator by cryptomator.

the class VaultSettingsJsonAdapterTest method testDeserialize.

@Test
public void testDeserialize() throws IOException {
    String json = "{\"id\": \"foo\", \"path\": \"/foo/bar\", \"mountName\": \"test\", \"winDriveLetter\": \"X\", \"shouldBeIgnored\": true}";
    JsonReader jsonReader = new JsonReader(new StringReader(json));
    Settings settings = Mockito.mock(Settings.class);
    VaultSettings vaultSettings = adapter.read(jsonReader, settings);
    Assert.assertEquals("foo", vaultSettings.getId());
    Assert.assertEquals(Paths.get("/foo/bar"), vaultSettings.path().get());
    Assert.assertEquals("test", vaultSettings.mountName().get());
    Assert.assertEquals("X", vaultSettings.winDriveLetter().get());
}
Also used : StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader) Test(org.junit.Test)

Example 60 with JsonReader

use of com.google.gson.stream.JsonReader in project buck by facebook.

the class WorkerProcessProtocolZeroTest method testReceiveCommandWithIncorrectMessageID.

@Test
public void testReceiveCommandWithIncorrectMessageID() throws IOException {
    int messageID = 123;
    int differentMessageID = 456;
    JsonReader jsonReader = createMockJsonReaderForReceiveCommand(differentMessageID, "command", "/path/to/args", "/path/to/stdout", "/path/to/stderr");
    WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, jsonReader, newTempFile());
    try {
        protocol.receiveCommand(messageID);
    } catch (HumanReadableException e) {
        assertThat(e.getMessage(), Matchers.containsString(String.format("Expected command's \"id\" value to be \"%d\"", messageID)));
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) JsonReader(com.google.gson.stream.JsonReader) Test(org.junit.Test)

Aggregations

JsonReader (com.google.gson.stream.JsonReader)95 StringReader (java.io.StringReader)36 JsonElement (com.google.gson.JsonElement)30 Test (org.junit.Test)19 JsonObject (com.google.gson.JsonObject)17 IOException (java.io.IOException)17 InputStreamReader (java.io.InputStreamReader)17 JsonParser (com.google.gson.JsonParser)11 HumanReadableException (com.facebook.buck.util.HumanReadableException)10 Gson (com.google.gson.Gson)9 TypeToken (com.google.gson.reflect.TypeToken)8 JsonWriter (com.google.gson.stream.JsonWriter)8 Map (java.util.Map)7 JsonToken (com.google.gson.stream.JsonToken)6 HashMap (java.util.HashMap)6 InputStream (java.io.InputStream)5 StringWriter (java.io.StringWriter)5 Type (java.lang.reflect.Type)5 ArrayList (java.util.ArrayList)5 BufferedReader (java.io.BufferedReader)4