use of com.google.gson.JsonElement in project che by eclipse.
the class JsonRpcParamsTest method shouldToJsonValueForParsedListDoubleParams.
@Test
public void shouldToJsonValueForParsedListDoubleParams() throws Exception {
Double expected = 0D;
JsonArray array = new JsonArray();
array.add(new JsonPrimitive(expected));
JsonRpcParams jsonRpcParams = new JsonRpcParams("[" + expected + "]", jsonParser);
JsonElement jsonValue = jsonRpcParams.toJsonElement();
assertEquals(array, jsonValue);
}
use of com.google.gson.JsonElement in project che by eclipse.
the class NodeJsBreakpointsParser method parse.
@Override
public Breakpoints parse(NodeJsOutput nodeJsOutput) throws NodeJsDebuggerParseException {
final List<Breakpoint> breakpoints = new ArrayList<>();
JsonObject json = new JsonParser().parse(nodeJsOutput.getOutput()).getAsJsonObject();
if (json.has("breakpoints")) {
Iterator<JsonElement> iter = json.getAsJsonArray("breakpoints").iterator();
while (iter.hasNext()) {
JsonObject item = iter.next().getAsJsonObject();
try {
final String condition = item.has("condition") && !item.get("condition").isJsonNull() ? item.get("condition").getAsString() : null;
final boolean isEnabled = item.has("active") && !item.get("active").isJsonNull() && item.get("active").getAsBoolean();
final int lineNumber = item.get("line").getAsInt();
final String target;
String targetType = item.get("type").getAsString();
switch(targetType) {
case "scriptId":
target = String.valueOf(item.get("script_id").getAsInt());
break;
case "scriptRegExp":
target = item.get("script_regexp").getAsString();
break;
default:
throw new IllegalArgumentException("Unsupported 'type' value: " + targetType);
}
Location location = new LocationImpl(targetType + ":" + target, lineNumber + 1);
Breakpoint breakpoint = new BreakpointImpl(location, isEnabled, condition);
breakpoints.add(breakpoint);
} catch (Exception e) {
LOG.error("Failed to parse breakpoint: " + item.toString(), e);
}
}
}
return new Breakpoints(breakpoints);
}
use of com.google.gson.JsonElement in project weave by continuuity.
the class LocalFileCodec method deserialize.
@Override
public LocalFile deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObj = json.getAsJsonObject();
String name = jsonObj.get("name").getAsString();
URI uri = URI.create(jsonObj.get("uri").getAsString());
long lastModified = jsonObj.get("lastModified").getAsLong();
long size = jsonObj.get("size").getAsLong();
boolean archive = jsonObj.get("archive").getAsBoolean();
JsonElement pattern = jsonObj.get("pattern");
return new DefaultLocalFile(name, uri, lastModified, size, archive, (pattern == null || pattern.isJsonNull()) ? null : pattern.getAsString());
}
use of com.google.gson.JsonElement in project weixin-java-tools by chanjarster.
the class WxMpServiceImpl method templateSend.
public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send";
String responseContent = execute(new SimplePostRequestExecutor(), url, templateMessage.toJson());
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
final JsonObject jsonObject = tmpJsonElement.getAsJsonObject();
if (jsonObject.get("errcode").getAsInt() == 0)
return jsonObject.get("msgid").getAsString();
throw new WxErrorException(WxError.fromJson(responseContent));
}
use of com.google.gson.JsonElement in project weixin-java-tools by chanjarster.
the class WxMpServiceImpl method getJsapiTicket.
public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
if (forceRefresh) {
wxMpConfigStorage.expireJsapiTicket();
}
if (wxMpConfigStorage.isJsapiTicketExpired()) {
synchronized (globalJsapiTicketRefreshLock) {
if (wxMpConfigStorage.isJsapiTicketExpired()) {
String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi";
String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
wxMpConfigStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds);
}
}
}
return wxMpConfigStorage.getJsapiTicket();
}
Aggregations