Examples of JsonElement


Examples of com.github.jsonj.JsonElement

        for(int i = 0; i<100000; i++) {
            tasks.add(new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    JsonElement output;
                    output = jsonParser.parse(input);
                    String serialized = JsonSerializer.serialize(output, false);
                    return input.equals(serialized);
                }
            });
View Full Code Here

Examples of com.github.jsonj.JsonElement

        };
    }

    @Test(dataProvider="strings")
    public void shouldParseSerializedAndHandleEscapingBothWays(String text) {
        JsonElement e = object().put(text, "value").put("stringval", text).put("array", array(text,text)).get();

        String json = JsonSerializer.serialize(e);
        JsonElement parsed = new JsonParser().parse(json);
        AssertJUnit.assertEquals(e, parsed);
    }
View Full Code Here

Examples of com.github.jsonj.JsonElement

        AssertJUnit.assertEquals(e, parsed);
    }

    @Test(dataProvider = "strings")
    public void shouldParseSerializedAndHandleEscapingBothWaysWithOutputStream(String text) throws IOException {
        JsonElement e = object().put(text, "value").put("stringval", text).put("array", array(text, text)).get();
        StringWriter sw = new StringWriter();

        JsonSerializer.serialize(e, sw);
        String string = sw.getBuffer().toString();
        JsonElement parsed = new JsonParser().parse(string);
        AssertJUnit.assertEquals(e, parsed);
    }
View Full Code Here

Examples of com.google.gson.JsonElement

public final class JsonToResource {
  private JsonToResource() {
  }

  public static Resource parse(InputStream inputStream) {
    JsonElement element = new JsonParser().parse(new InputStreamReader(inputStream));
    return parseResource(element.getAsJsonObject(), "/", null);
  }
View Full Code Here

Examples of com.google.gson.JsonElement

  private static Resource parseResource(JsonObject object, String name, Resource parent) {
    Map<String, String> properties = new LinkedHashMap<String, String>();
    Map<String, JsonObject> children = new LinkedHashMap<String, JsonObject>();
    for (Entry<String, JsonElement> entry : object.entrySet()) {
      JsonElement value = entry.getValue();
      if (value.isJsonPrimitive()) {
        properties.put(entry.getKey(), value.getAsString());
      } else if (value.isJsonObject()) {
        children.put(entry.getKey(), value.getAsJsonObject());
      }
    }

    ResourceMock resource = new ResourceMock(parent, name);
    for (Entry<String, String> entry : properties.entrySet()) {
View Full Code Here

Examples of com.google.gson.JsonElement

     * @param gson the gson instance to use
     * @param json the json response content
     * @return the InstagramErrorResponse object
     */
    public static InstagramErrorResponse parse(Gson gson, String json) {
        JsonElement jsonElement = gson.fromJson(json, JsonElement.class);
        JsonElement metaMember = jsonElement.getAsJsonObject().get("meta");
        final Meta meta;
        if (metaMember != null) {
            meta = gson.fromJson(metaMember, Meta.class);
        } else {
            meta = gson.fromJson(jsonElement, Meta.class);
View Full Code Here

Examples of com.google.gson.JsonElement

   *            the json content
   * @return the json element
   */
  private JsonElement unmarshallToJson(InputStream jsonContent) {
    try {
      JsonElement element = parser.parse(new InputStreamReader(
          jsonContent,
          UTF_8_CHAR_SET));
      if (element.isJsonObject()) {
        return element.getAsJsonObject();
      } else if (element.isJsonArray()) {
        return element.getAsJsonArray();
      } else {
        throw new IllegalStateException(
            "Unknown content found in response." + element);
      }
    } catch (Exception e) {
View Full Code Here

Examples of com.google.gson.JsonElement

    // Get metadata for the Module
    List<JsonElement> requestElements = new ArrayList<JsonElement>();
    JsonObject moduleJsonObject = gson.fromJson(output, JsonObject.class);

    JsonElement moduleNameElement = moduleJsonObject.get("moduleName");
    JsonElement moduleDescriptionElement = moduleJsonObject.get("moduleDescription");
    JsonElement moduleVersionElement = moduleJsonObject.get("moduleDescription");

    String moduleName = "default_module_name";
    String moduleDescription = "default_module_description";
    String moduleVersion = "1.0";

    if (moduleNameElement != null && !moduleNameElement.getAsString().isEmpty()) {
      moduleName = moduleNameElement.getAsString();
    }

    if (moduleDescriptionElement != null && !moduleDescriptionElement.getAsString().isEmpty()) {
      moduleDescription = moduleDescriptionElement.getAsString();
    }
   
    if (moduleVersionElement != null && !moduleDescriptionElement.getAsString().isEmpty()) {
      moduleDescription = moduleVersionElement.getAsString();
    }

    // Get all 'functions' as JsonObjects from the file and add them as a
    // list
    JsonElement functions = JsonUtils.findElement(moduleJsonObject, "functions");
    if (functions != null) {
      if (functions.isJsonArray()) {
        JsonArray requests_array = functions.getAsJsonArray();
        for (JsonElement requestElement : requests_array) {
          if (requestElement.isJsonObject()) {
            JsonObject request = requestElement.getAsJsonObject();
            requestElements.add(request);
          }
View Full Code Here

Examples of com.google.gson.JsonElement

    stack.add(element);
    return search(stack, elementName);
  }

  private static JsonElement search(Queue<JsonElement> queue, String elementName) {
    JsonElement ret = null;
    while (queue.size() > 0) {
      JsonElement element = queue.poll();
      if (element.isJsonObject()) {
        JsonObject object = element.getAsJsonObject();
        Set<Entry<String, JsonElement>> members = object.entrySet();
        for (Entry<String, JsonElement> member : members) {
          if (member.getKey().equals(elementName)) {
            return member.getValue();
          } else {
            queue.add(member.getValue());
          }
        }

      } else if (element.isJsonArray()) {
        JsonArray array = element.getAsJsonArray();
        for (JsonElement array_element : array) {
          queue.add(array_element);
        }
      }
    }
View Full Code Here

Examples of com.google.gson.JsonElement

    this.setPostData(JsonUtils.findElement(jsonRequest, "postData"));
    this.setResponseFields(JsonUtils.findElement(jsonRequest, "response"));
  }
 
  private void setResponseFields(JsonElement jsonResponse) {
    JsonElement responseFields = null;
    if(jsonResponse != null) responseFields = JsonUtils.findElement(jsonResponse, "fields");
   
    if (responseFields != null) {
      for (JsonElement responseField : JsonUtils.asJsonArray(responseFields)) {
        JsonObject response = JsonUtils.asJsonObject(responseField);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.