Search in sources :

Example 61 with JsonReader

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

the class WxCpServiceImpl method departGetUsers.

@Override
public List<WxCpUser> departGetUsers(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException {
    String url = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?department_id=" + departId;
    String params = "";
    if (fetchChild != null) {
        params += "&fetch_child=" + (fetchChild ? "1" : "0");
    }
    if (status != null) {
        params += "&status=" + status;
    } else {
        params += "&status=0";
    }
    String responseContent = get(url, params);
    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
    return WxCpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("userlist"), new TypeToken<List<WxCpUser>>() {
    }.getType());
}
Also used : WxCpUser(me.chanjar.weixin.cp.bean.WxCpUser) JsonElement(com.google.gson.JsonElement) TypeToken(com.google.gson.reflect.TypeToken) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader)

Example 62 with JsonReader

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

the class WxCpServiceImpl method invite.

@Override
public int invite(String userId, String inviteTips) throws WxErrorException {
    String url = "https://qyapi.weixin.qq.com/cgi-bin/invite/send";
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("userid", userId);
    if (StringUtils.isNotEmpty(inviteTips)) {
        jsonObject.addProperty("invite_tips", inviteTips);
    }
    String responseContent = post(url, jsonObject.toString());
    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
    return tmpJsonElement.getAsJsonObject().get("type").getAsInt();
}
Also used : JsonElement(com.google.gson.JsonElement) StringReader(java.io.StringReader) JsonObject(com.google.gson.JsonObject) JsonReader(com.google.gson.stream.JsonReader)

Example 63 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 64 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 65 with JsonReader

use of com.google.gson.stream.JsonReader in project zeppelin by apache.

the class NotebookTypeAdapterFactory method customizeTypeAdapter.

private TypeAdapter<C> customizeTypeAdapter(Gson gson, TypeToken<C> type) {
    final TypeAdapter<C> delegate = gson.getDelegateAdapter(this, type);
    final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
    return new TypeAdapter<C>() {

        @Override
        public void write(JsonWriter out, C value) throws IOException {
            JsonElement tree = delegate.toJsonTree(value);
            beforeWrite(value, tree);
            elementAdapter.write(out, tree);
        }

        @Override
        public C read(JsonReader in) throws IOException {
            JsonElement tree = elementAdapter.read(in);
            afterRead(tree);
            return delegate.fromJsonTree(tree);
        }
    };
}
Also used : JsonElement(com.google.gson.JsonElement) TypeAdapter(com.google.gson.TypeAdapter) JsonReader(com.google.gson.stream.JsonReader) JsonWriter(com.google.gson.stream.JsonWriter)

Aggregations

JsonReader (com.google.gson.stream.JsonReader)100 StringReader (java.io.StringReader)38 JsonElement (com.google.gson.JsonElement)31 IOException (java.io.IOException)20 JsonObject (com.google.gson.JsonObject)19 Test (org.junit.Test)19 InputStreamReader (java.io.InputStreamReader)18 JsonParser (com.google.gson.JsonParser)12 HumanReadableException (com.facebook.buck.util.HumanReadableException)10 Gson (com.google.gson.Gson)10 JsonWriter (com.google.gson.stream.JsonWriter)10 TypeToken (com.google.gson.reflect.TypeToken)8 Map (java.util.Map)8 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 GsonBuilder (com.google.gson.GsonBuilder)4