List of usage examples for com.google.gson JsonElement toString
@Override
public String toString()
From source file:org.apache.tika.langdetect.TextLangDetector.java
License:Apache License
private Set<String> getAllLanguages() { Set<String> languages = new HashSet<>(); try {/* ww w . j av a 2 s . c om*/ Response response = WebClient.create(restHostUrlStr + TEXT_LID_PATH).get(); String json = response.readEntity(String.class); JsonArray jsonArray = new JsonParser().parse(json).getAsJsonObject().get("all_languages") .getAsJsonArray(); for (JsonElement jsonElement : jsonArray) { languages.add(jsonElement.toString()); } } catch (Exception e) { e.printStackTrace(); } return languages; }
From source file:org.apache.twill.internal.json.JsonUtils.java
License:Apache License
/** * Returns a String representation of the given property. *///ww w. j a v a 2 s . c o m public static String getAsString(JsonObject json, String property) { JsonElement jsonElement = json.get(property); if (jsonElement == null || jsonElement.isJsonNull()) { return null; } if (jsonElement.isJsonPrimitive()) { return jsonElement.getAsString(); } return jsonElement.toString(); }
From source file:org.apache.zeppelin.rest.AbstractTestRestApi.java
License:Apache License
protected TypeSafeMatcher<? super JsonElement> hasRootElementNamed(final String memberName) { return new TypeSafeMatcher<JsonElement>() { @Override//w w w . j ava 2s . co m protected boolean matchesSafely(JsonElement item) { return item.isJsonObject() && item.getAsJsonObject().has(memberName); } @Override public void describeTo(Description description) { description.appendText("response in JSON format with \"").appendText(memberName) .appendText("\" beeing a root element "); } @Override protected void describeMismatchSafely(JsonElement root, Description description) { description.appendText("got ").appendText(root.toString()); } }; }
From source file:org.blockartistry.DynSurround.client.footsteps.parsers.AcousticsJsonReader.java
License:MIT License
private IAcoustic solveAcoustic(final JsonElement unsolved) throws JsonParseException { IAcoustic ret = null;/*from w w w . jav a 2s. c o m*/ if (unsolved.isJsonObject()) { ret = solveAcousticsCompound(unsolved.getAsJsonObject()); } else if (unsolved.isJsonPrimitive() && unsolved.getAsJsonPrimitive().isString()) { // Is a sound name final BasicAcoustic a = new BasicAcoustic(); prepareDefaults(a); setupSoundName(a, unsolved.getAsString()); ret = a; } if (ret == null) throw new JsonParseException("Unresolved Json element: \r\n" + unsolved.toString()); return ret; }
From source file:org.cinchapi.concourse.util.Convert.java
License:Open Source License
/** * Convert a {@link JsonElement} to a a Java object and respect the desire * to force a numeric string to a double. * //from w w w . j a v a2s. c o m * @param element * @return the java object */ private static Object jsonElementToJava(JsonElement element) { if (element.getAsString().matches("-?[0-9]+\\.[0-9]+D")) { return stringToJava(element.getAsString()); // respect desire // to force double } else if (element.getAsString().matches("`([^`]+)`")) { return stringToJava(element.getAsString()); // CON-137 } else if (element.getAsString().matches(MessageFormat.format("{0}{1}{0}", MessageFormat.format("{0}{1}{2}", RAW_RESOLVABLE_LINK_SYMBOL_PREPEND, ".+", RAW_RESOLVABLE_LINK_SYMBOL_APPEND), ".+"))) { return stringToJava(element.getAsString()); // respect resolvable // link specification } else { return stringToJava(element.toString()); } }
From source file:org.cloudfoundry.community.servicebroker.vrealize.VraClient.java
License:Open Source License
public VrServiceInstance createInstance(CreateServiceInstanceRequest request, ServiceDefinition sd) { try {/*from w w w. ja v a 2 s . c o m*/ LOG.info("creating instance."); VrServiceInstance instance = new VrServiceInstance(request); String token = tokenService.getToken(); LOG.info("getting a template for the create request."); JsonElement template = getCreateRequestTemplate(token, sd); String serviceType = getServiceType(template); LOG.debug("template for create request: " + template.toString()); LOG.info("customizing the create template."); JsonObject edited = prepareCreateRequestTemplate(template, instance); LOG.debug("customed create template: " + edited.toString()); LOG.info("posting the create request."); ResponseEntity<JsonElement> response = postCreateRequest(token, edited, sd); LOG.debug("service request response: " + response.toString()); String location = getLocation(response); String requestId = getRequestId(response.getBody()); LOG.info("loading metadata onto instance from catalog item request response."); instance.getMetadata().put(VrServiceInstance.LOCATION, location); instance.getMetadata().put(VrServiceInstance.CREATE_REQUEST_ID, requestId); instance.setServiceType(serviceType); LastOperation lo = new LastOperation(OperationState.IN_PROGRESS, requestId, false); instance.withLastOperation(lo); return instance; } catch (Throwable t) { LOG.error("error processing create request.", t); throw new ServiceBrokerException("Unable to process create request.", t); } }
From source file:org.cloudfoundry.community.servicebroker.vrealize.VraClient.java
License:Open Source License
public void loadCredentials(VrServiceInstance instance) { String token = tokenService.getToken(); LOG.info("loading host for request: " + instance.getCreateRequestId()); JsonElement resourcesResponse = vraRepository .getRequestResources("Bearer " + token, instance.getCreateRequestId()).getBody(); LOG.debug("loading credentials from: " + instance.getLocation().toString() + ": " + resourcesResponse.toString()); instance.getMetadata().putAll(getLinks(resourcesResponse)); LOG.debug("loading host from response: " + resourcesResponse.toString()); instance.getMetadata().put(VrServiceInstance.HOST, getHostIP(resourcesResponse)); }
From source file:org.cloudfoundry.community.servicebroker.vrealize.VraClient.java
License:Open Source License
JsonObject prepareCreateRequestTemplate(JsonElement template, VrServiceInstance serviceInstance) { DocumentContext ctx = JsonPath.parse(template.toString()); String serviceType = ctx.read("$.data.SERVICE_TYPE"); serviceInstance.setServiceType(serviceType); Adaptor adaptor = Adaptors.getAdaptor(serviceType); if (adaptor == null) { throw new ServiceBrokerException("service adaptor not found for SERVICE_TYPE: " + serviceType); }// w ww . jav a 2s .c o m //add service specific information onto the request adaptor.prepareRequest(ctx, serviceInstance); //add some identifying information onto the request ctx.set("$.description", serviceInstance.getId()); ctx.set("$.reasons", "CF vRA Service Broker request."); return new Gson().fromJson(ctx.jsonString(), JsonElement.class).getAsJsonObject(); }
From source file:org.cloudfoundry.community.servicebroker.vrealize.VraClient.java
License:Open Source License
String getServiceType(JsonElement requestResponse) { if (requestResponse == null) { return null; }/*from www. ja va2s . c om*/ ReadContext ctx = JsonPath.parse(requestResponse.toString()); return ctx.read("$.data." + VrServiceInstance.SERVICE_TYPE); }
From source file:org.cloudfoundry.community.servicebroker.vrealize.VraClient.java
License:Open Source License
String getHostIP(JsonElement requestResponse) { if (requestResponse == null) { return null; }//from w ww . ja v a 2s . com ReadContext ctx = JsonPath.parse(requestResponse.toString()); JSONArray o = ctx.read("$.content[*].data.ip_address"); if (o == null || o.size() < 1 || o.get(0) == null) { return null; } return o.get(0).toString(); }