Package com.google.gson

Examples of com.google.gson.JsonParser


        JsonObject resp = new JsonObject();
        resp.addProperty("jsonrpc", "2.0");
        JsonObject error = new JsonObject();
        error.addProperty("code", -32002);
        error.addProperty("message", "service.invalid-parameters");
        error.add("data", new JsonParser().parse("{\"email\":[\"'email' is no valid email address in the basic format local-part@hostname\"]}}"));
        resp.add("error", error);

        TestInterface handle = invoker.get(getTransport(resp), "someHandler", TestInterface.class);

        try {
View Full Code Here


        } catch (Exception e) {
            throw new JsonRpcClientException("unable to get data from transport", e);
        }
        LOG.debug("JSON-RPC <<  {}", responseData);

        JsonParser parser = new JsonParser();
        JsonObject resp = (JsonObject) parser.parse(new StringReader(responseData));

        JsonElement result = resp.get("result");
        JsonElement error = resp.get("error");

        if (error != null && !error.isJsonNull()) {
View Full Code Here

    // Reconstruct the original wavelet. This is a "blind" wavelet since any
    // operations applied to this wavelet are done without us really knowing
    // what the state of the wavelet is (it might have changed on the server).
    // This means we have to be careful.
    JsonObject json = new JsonParser().parse(e.getMessage()).getAsJsonObject();
    WaveletData waveletData = SERIALIZER.fromJson(json.get("wavelet"), WaveletData.class);
    BlipData blipData = SERIALIZER.fromJson(json.get("blip"), BlipData.class);
    OperationQueue operationQueue = new OperationQueue();

    Map<String, Blip> blips = new HashMap<String, Blip>();
View Full Code Here

   }

   // inspired by
   // http://code.google.com/p/google-gson/source/browse/trunk/extras/src/main/java/com/google/gson/extras/examples/rawcollections/RawCollectionsExample.java
   public void testRawCollectionsWithParser() {
      JsonParser parser = new JsonParser();
      JsonArray array = parser.parse(json).getAsJsonArray();
      String message = gson.fromJson(array.get(0), String.class);
      int number = gson.fromJson(array.get(1), int.class);
      Event event = gson.fromJson(array.get(2), Event.class);
      assertEquals(message, "hello");
      assertEquals(number, 5);
View Full Code Here

                jsonType = type;
            } else {
                jsonType = genericType;
            }
            if (JsonElement.class.isAssignableFrom(type)) {
                JsonParser parser = new JsonParser();
                JsonElement jsonElement = parser.parse(streamReader);
                return jsonElement;
            } else {
                throw new IllegalArgumentException();

                // Gson gson = getGson();
View Full Code Here

    }

    private <T> List<T> readList(String json, Class<T> clazz) throws RestClientException {
        List<T> ret = new ArrayList<T>();
        try {
            JsonParser parser = new JsonParser();
            JsonArray array = parser.parse(json).getAsJsonArray();
            for (int i = 0; i < array.size(); i++) {
                T next = gson.fromJson(array.get(i), clazz);
                ret.add(next);
            }
        } catch (JsonParseException e) {
View Full Code Here

    public Metadata getMetadata() throws RestClientException {
        HttpRequest request = buildGet("openstack/latest/meta_data.json");

        String json = doStringRequest(request);

        JsonObject metadata = (JsonObject) new JsonParser().parse(json);

        return new Metadata(metadata);
    }
View Full Code Here

    }
    return response;
  }
 
  private JsonElement execute(String url, JsonElement request) throws IOException {
    return new JsonParser().parse(execute(url, request.toString()));
  }
View Full Code Here

   * Legge il body della richiesta, trasforma la stringa json in un oggetto
   * @return oggetto json
   */
  protected final JsonElement loadGSONRequestBody() {
   
    JsonParser parser = new JsonParser();
   
    return parser.parse( readRequestBody() );   
  }
View Full Code Here

    try {
      String content = getContentOfStream(inputStream);
      logger.debug("json retrieved: {}", content);
     
      if (!isNullOrEmpty(content)) {
        JsonParser parser = new JsonParser();
        JsonElement jsonElement = parser.parse(content);
        if (jsonElement.isJsonObject()) {
          JsonObject root = jsonElement.getAsJsonObject();
   
          for (int i = 0; i < types.length; i++) {
            Parameter parameter = parameterNames[i];
View Full Code Here

TOP

Related Classes of com.google.gson.JsonParser

Copyright © 2018 www.massapicom. 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.