public ANResponse executeForObjectList(Class objectClass) { this.mType = $Gson$Types.newParameterizedTypeWithOwner(null, List.class, objectClass); this.mResponseType = ResponseType.PARSED; return SynchronousCall.execute(this); }
static Type getSuperclassTypeParameter(Class<?> subclass) { Type superclass = subclass.getGenericSuperclass(); if (superclass instanceof Class) { throw new RuntimeException("Missing type parameter."); } ParameterizedType parameterized = (ParameterizedType) superclass; return $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[0]); }
/** * Gets the value of data that is keyed to the provided {@link Key} at the * give block location. The data may not exist, or may not be compatible in * which case the default value may be returned. * * @param x The X position * @param y The Y position * @param z The Z position * @param key The key to the data * @param defaultValue The default value to return * @param <E> The type of element of data * @return The data or null */ default <E> E getOrElse(int x, int y, int z, Key<? extends BaseValue<E>> key, E defaultValue) { return get(x, y, z, key).orElse(checkNotNull(defaultValue)); }
@Override public String tagCreate(String tagName) throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/create"; JsonObject o = new JsonObject(); o.addProperty("tagname", tagName); String responseContent = post(url, o.toString()); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); return tmpJsonElement.getAsJsonObject().get("tagid").getAsString(); }
@Override public void write(JsonWriter out, T value) throws IOException { if (value == null) { out.nullValue(); return; } JsonElement tree = serializer.serialize(value, typeToken.getType(), (JsonSerializationContext) ReflectionUtil.readField(gson, "serializationContext")); Streams.write(tree, out); } }
@Override public R read(JsonReader in) throws IOException { JsonElement jsonElement = Streams.parse(in); JsonElement labelJsonElement = jsonElement.getAsJsonObject().remove(typeFieldName); String label = (labelJsonElement == null ? null : labelJsonElement.getAsString()); @SuppressWarnings("unchecked") // registration requires that subtype extends T TypeAdapter<R> delegate = (TypeAdapter<R>) labelToDelegate.get(label); if (delegate == null) { throw new JsonParseException("cannot deserialize " + baseType + " subtype named " + label + "; did you forget to register a subtype?"); } return delegate.fromJsonTree(jsonElement); }
public void getAsObjectList(Class objectClass, ParsedRequestListener parsedRequestListener) { this.mType = $Gson$Types.newParameterizedTypeWithOwner(null, List.class, objectClass); this.mResponseType = ResponseType.PARSED; this.mParsedRequestListener = parsedRequestListener; ANRequestQueue.getInstance().addRequest(this); }
/** * Gets the value of data that is keyed to the provided {@link Key} at the * give block location. The data may not exist, or may not be compatible in * which case the default value may be returned. * * @param coordinates The position of the block * @param key The key to the data * @param defaultValue The default value to be provided * @param <E> The type of element of data * @return The data or null */ default <E> E getOrElse(Vector3i coordinates, Key<? extends BaseValue<E>> key, E defaultValue) { return get(coordinates.getX(), coordinates.getY(), coordinates.getZ(), key).orElse(checkNotNull(defaultValue)); }
@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; }
public void getAsOkHttpResponseAndObjectList(Class objectClass, OkHttpResponseAndParsedRequestListener parsedRequestListener) { this.mType = $Gson$Types.newParameterizedTypeWithOwner(null, List.class, objectClass); this.mResponseType = ResponseType.PARSED; this.mOkHttpResponseAndParsedRequestListener = parsedRequestListener; ANRequestQueue.getInstance().addRequest(this); }
@Override public String[] getCallbackIp() throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/getcallbackip"; String responseContent = get(url, null); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); JsonArray jsonArray = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray(); String[] ips = new String[jsonArray.size()]; for(int i = 0; i < jsonArray.size(); i++) { ips[i] = jsonArray.get(i).getAsString(); } return ips; }
@Override public ObservableSource<? extends Boolean> apply(Boolean isEmpty) throws Exception { if (isEmpty) { Type type = $Gson$Types .newParameterizedTypeWithOwner(null, List.class, Question.class); List<Question> questionList = gson.fromJson( CommonUtils.loadJSONFromAsset(mContext, AppConstants.SEED_DATABASE_QUESTIONS), type); return saveQuestionList(questionList); } return Observable.just(false); } });
@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(); }
public <T> Observable<List<T>> getObjectListObservable(Class<T> objectClass) { this.setType($Gson$Types.newParameterizedTypeWithOwner(null, List.class, objectClass)); this.setResponseAs(ResponseType.PARSED); if (this.getRequestType() == RequestType.SIMPLE) { return Rx2InternalNetworking.generateSimpleObservable(this); } else if (this.getRequestType() == RequestType.MULTIPART) { return Rx2InternalNetworking.generateMultipartObservable(this); } else { return null; } }
public String shortUrl(String long_url) throws WxErrorException { String url = "https://api.weixin.qq.com/cgi-bin/shorturl"; JsonObject o = new JsonObject(); o.addProperty("action", "long2short"); o.addProperty("long_url", long_url); String responseContent = execute(new SimplePostRequestExecutor(), url, o.toString()); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); return tmpJsonElement.getAsJsonObject().get("short_url").getAsString(); }
public <T> Observable<List<T>> getObjectListObservable(Class<T> objectClass) { this.setType($Gson$Types.newParameterizedTypeWithOwner(null, List.class, objectClass)); this.setResponseAs(ResponseType.PARSED); if (this.getRequestType() == RequestType.SIMPLE) { return RxInternalNetworking.generateSimpleObservable(this); } else if (this.getRequestType() == RequestType.MULTIPART) { return RxInternalNetworking.generateMultipartObservable(this); } else { return null; } }
@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")}; }
@Override public R read(JsonReader in) throws IOException { JsonElement jsonElement = Streams.parse(in); JsonElement labelJsonElement = jsonElement.getAsJsonObject().remove(typeFieldName); if (labelJsonElement == null) { throw new JsonParseException("cannot deserialize " + baseType + " because it does not define a field named " + typeFieldName); } String label = labelJsonElement.getAsString(); @SuppressWarnings("unchecked") // registration requires that subtype extends T TypeAdapter<R> delegate = (TypeAdapter<R>) labelToDelegate.get(label); if (delegate == null) { throw new JsonParseException("cannot deserialize " + baseType + " subtype named " + label + "; did you forget to register a subtype?"); } return delegate.fromJsonTree(jsonElement); }
public long userGetGroup(String openid) throws WxErrorException { String url = "https://api.weixin.qq.com/cgi-bin/groups/getid"; JsonObject o = new JsonObject(); o.addProperty("openid", openid); String responseContent = execute(new SimplePostRequestExecutor(), url, o.toString()); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); return GsonHelper.getAsLong(tmpJsonElement.getAsJsonObject().get("groupid")); }
@Override public T read(JsonReader in) throws IOException { JsonElement value = Streams.parse(in); if (value.isJsonNull()) { return null; } return deserializer.deserialize(value, typeToken.getType(), (JsonDeserializationContext) ReflectionUtil.readField(gson, "deserializationContext")); }