Examples of JsonElement


Examples of com.baidu.gson.JsonElement

  public String invoke(String host, String[] serviceAndMethod, String input)
      throws Throwable {
    try {
      int id = counter.getAndIncrement();
      JsonElement request = makeRequest(id, serviceAndMethod, input);
      byte[] reqBytes = serialize(request);
      // log.debug("request bytes size is " + reqBytes.length);
     
      String url = host + serviceAndMethod[0];
     
      log.info("input: " + input);
      log.info("url: " + url);
     
      HttpURLConnection connection = (HttpURLConnection) new URL(url)
          .openConnection();
      if (_connectTimeout > 0) {
        connection.setConnectTimeout(_connectTimeout);
      }
      if (_readTimeout > 0) {
        connection.setReadTimeout(_readTimeout);
      }
      sendRequest(reqBytes, connection);
      byte[] resBytes = null;
      resBytes = readResponse(connection);
      JsonElement resJson = deserialize(resBytes);
//      return parseResult(id, resJson, method);
      return resJson.toString();
    } catch (IOException e) {
      throw new InternalErrorException(e);
    }
  }
View Full Code Here

Examples of com.github.jsonj.JsonElement

     * @param lineString 2d JsonArray
     * @return 3d double array with the polygon
     */
    public static JsonArray lineStringToPolygon(JsonArray lineString) {
        if(!lineString.first().equals(lineString.last())) {
            JsonElement e = lineString.first().deepClone();
            lineString.add(e);
        }
        return array(lineString);
    }
View Full Code Here

Examples of com.github.jsonj.JsonElement

            }
        } else {
            if(array.size() < 2) {
                throw new IllegalArgumentException("need at least two coordinates");
            }
            JsonElement first = array.get(0);
            JsonElement second = array.get(1);
            array.set(0, second);
            array.set(1, first);

        }
        return array;
View Full Code Here

Examples of com.github.jsonj.JsonElement

            try {
                child = new Element(entry.getKey());
            } catch (IllegalNameException exc1) {
                child = new Element("_" + entry.getKey());
            }
            JsonElement value = entry.getValue();
            if(value.isArray()) {
                append(child, value.asArray());
            } else if(value.isObject()) {
                append(child, value.asObject());
            } else {
                append(child, value.asPrimitive());
            }

            e.appendChild(child);
        }
    }
View Full Code Here

Examples of com.github.jsonj.JsonElement

            newline(bw, indent+1, pretty);
            Iterator<Entry<String, JsonElement>> iterator = json.asObject().entrySet().iterator();
            while (iterator.hasNext()) {
                Entry<String, JsonElement> entry = iterator.next();
                String key = entry.getKey();
                JsonElement value = entry.getValue();
                if(value != null) {
                    bw.write('"');
                    bw.write(jsonEscape(key));
                    bw.write("\":");
                    serialize(bw,value,pretty,indent+1);
                    if(iterator.hasNext()) {
                        bw.write(',');
                        newline(bw, indent+1, pretty);
                    }
                }
            }
            newline(bw, indent, pretty);
            bw.write('}');
            break;
        case array:
            bw.write('[');
            newline(bw, indent+1, pretty);
            Iterator<JsonElement> arrayIterator = json.asArray().iterator();
            while (arrayIterator.hasNext()) {
                JsonElement value = arrayIterator.next();
                boolean nestedPretty=false;
                if(value.isObject()) {
                    nestedPretty=true;
                }
                serialize(bw,value,nestedPretty,indent+1);
                if(arrayIterator.hasNext()) {
                    bw.write(',');
View Full Code Here

Examples of com.github.jsonj.JsonElement

        JsonPrimitive primitive;
        primitive = new JsonPrimitive(object);
        if (isObject) {
            stack.add(primitive);
        } else {
            JsonElement peekLast = stack.peekLast();
            if (peekLast instanceof JsonArray) {
                peekLast.asArray().add(primitive);
            } else {
                stack.add(primitive);
            }
        }
        return true;
View Full Code Here

Examples of com.github.jsonj.JsonElement

        }
        return true;
    }

    public boolean endObjectEntry() {
        JsonElement value = stack.pollLast();
        JsonElement e = stack.peekLast();
        if (e.isPrimitive()) {
            e = stack.pollLast();
            JsonElement last = stack.peekLast();
            if (last.isObject()) {
                JsonObject container = last.asObject();
                String key = e.asPrimitive().asString();
                container.put(key, value);
            } else if (last.isArray()) {
                throw new IllegalStateException("shouldn't happen");

            }
        }
        return true;
View Full Code Here

Examples of com.github.jsonj.JsonElement

        return true;
    }

    public boolean endObject() {
        if (stack.size() > 1 && stack.get(stack.size() - 2).isArray()) {
            JsonElement object = stack.pollLast();
            stack.peekLast().asArray().add(object);
        }
        return true;
    }
View Full Code Here

Examples of com.github.jsonj.JsonElement

    public void endJSON() {
    }

    public boolean endArray() {
        if (stack.size() > 1 && stack.get(stack.size() - 2).isArray()) {
            JsonElement value = stack.pollLast();
            stack.peekLast().asArray().add(value);
        }
        return true;
    }
View Full Code Here

Examples of com.github.jsonj.JsonElement

    }

    @Test(dataProvider="goodJson")
    public void shouldParse(final JsonElement element) {
        String input = JsonSerializer.serialize(element, false);
        JsonElement parsed = jsonParser.parse(input);
        Assert.assertEquals(JsonSerializer.serialize(parsed, false), input);
        // check with the other parser as well
    }
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.