use of com.google.gson.stream.JsonReader in project weixin-java-tools by chanjarster.
the class WxMpServiceImpl method getUserSummary.
@Override
public List<WxMpUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException {
String url = "https://api.weixin.qq.com/datacube/getusersummary";
JsonObject param = new JsonObject();
param.addProperty("begin_date", SIMPLE_DATE_FORMAT.format(beginDate));
param.addProperty("end_date", SIMPLE_DATE_FORMAT.format(endDate));
String responseContent = post(url, param.toString());
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"), new TypeToken<List<WxMpUserSummary>>() {
}.getType());
}
use of com.google.gson.stream.JsonReader in project weixin-java-tools by chanjarster.
the class WxMpServiceImpl method getUserCumulate.
@Override
public List<WxMpUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException {
String url = "https://api.weixin.qq.com/datacube/getusercumulate";
JsonObject param = new JsonObject();
param.addProperty("begin_date", SIMPLE_DATE_FORMAT.format(beginDate));
param.addProperty("end_date", SIMPLE_DATE_FORMAT.format(endDate));
String responseContent = post(url, param.toString());
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"), new TypeToken<List<WxMpUserCumulate>>() {
}.getType());
}
use of com.google.gson.stream.JsonReader in project weixin-java-tools by chanjarster.
the class WxMpServiceImpl method shortUrl.
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();
}
use of com.google.gson.stream.JsonReader in project zipkin by openzipkin.
the class JsonCodec method readTraces.
public List<List<Span>> readTraces(byte[] bytes) {
JsonReader reader = jsonReader(bytes);
// cause we don't know how long it will be
List<List<Span>> result = new LinkedList<>();
try {
reader.beginArray();
while (reader.hasNext()) {
reader.beginArray();
// cause we don't know how long it will be
List<Span> trace = new LinkedList<>();
while (reader.hasNext()) {
trace.add(SPAN_ADAPTER.fromJson(reader));
}
reader.endArray();
result.add(trace);
}
reader.endArray();
return result;
} catch (Exception e) {
throw exceptionReading("List<List<Span>>", bytes, e);
}
}
use of com.google.gson.stream.JsonReader in project zipkin by openzipkin.
the class JsonCodec method readList.
static <T> List<T> readList(JsonAdapter<T> adapter, byte[] bytes) {
JsonReader reader = jsonReader(bytes);
List<T> result;
try {
reader.beginArray();
if (reader.hasNext()) {
// cause we don't know how long it will be
result = new LinkedList<>();
} else {
result = Collections.emptyList();
}
while (reader.hasNext()) {
result.add(adapter.fromJson(reader));
}
reader.endArray();
return result;
} catch (Exception e) {
throw exceptionReading("List<" + adapter + ">", bytes, e);
}
}
Aggregations