Package com.google.gson

Examples of com.google.gson.JsonParser


   * @throws GsonException
   */
  public static <T extends GsonSerializable> void parseJson(T object,
      Gson gson, String json, RawStringData data) throws GsonException {
    try {
      JsonElement root = new JsonParser().parse(json);
      object.fromGson(root, gson, data);
    } catch (JsonParseException e) {
      throw new GsonException("Unable to parse Json", e);
    }
  }
View Full Code Here


      currentUserWavesView.put(waveId, waveletId);
    }
  }

  private static JsonArray extractDocsJson(InputStreamReader isr) {
    JsonObject json = new JsonParser().parse(isr).getAsJsonObject();
    JsonObject responseJson = json.getAsJsonObject("response");
    JsonArray docsJson = responseJson.getAsJsonArray("docs");
    return docsJson;
  }
View Full Code Here

      throw new IllegalArgumentException(
          "The serializer map does not contain a serializer for the default protocol version");
    }
    this.gsons = gsons;
    this.defaultProtocolVersion = defaultProtocolVersion;
    this.jsonParser = new JsonParser();
  }
View Full Code Here

    private void handleSignatureRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException
    {
        resp.setContentType("application/json");
        resp.setStatus(200);

        JsonParser jsonParser = new JsonParser();
        JsonElement contentJson = jsonParser.parse(req.getReader());
        JsonObject jsonObject = contentJson.getAsJsonObject();
        JsonElement headers = jsonObject.get("headers");
        JsonObject response = new JsonObject();
        String signature;
View Full Code Here

    int index = textType.getSelectionIndex();
    if (index == 0) {
      text.setText(value);
    } else if (index == 1) {
      Gson gson = new GsonBuilder().setPrettyPrinting().create();
      JsonParser jp = new JsonParser();
      try {
        JsonElement je = jp.parse(value);
        String prettyJsonString = gson.toJson(je);
        text.setText(prettyJsonString);
      } catch (JsonSyntaxException e) {
        textType.select(currentTextType);
        throw new RuntimeException(RedisClient.i18nFile.getText(I18nFile.JSONEXCEPTION));
View Full Code Here

               });

               return diff.identical();
            }
            case JSON: {              
               JsonParser parser = new JsonParser();
               JsonElement payloadA = parser.parse(Strings2.toString(a.getPayload()));
               JsonElement payloadB = parser.parse(Strings2.toString(b.getPayload()));
               return Objects.equal(payloadA, payloadB);
            }
            default: {
               return Objects.equal(a, b);
            }
View Full Code Here

      return xml;
    }
  }

  private String formatJson(final String json) {
    return new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create().toJson(new JsonParser().parse(json));
  }
View Full Code Here

        .addValueReader(valueReader);
  }

  public void shouldMapFromJsonElement() throws Exception {
    String orderJson = "{\"id\":456, \"customer\":{\"id\":789, \"street_address\":\"123 Main Street\", \"address_city\":\"SF\"}}";
    JsonParser jsonParser = new JsonParser();
    JsonElement element = jsonParser.parse(orderJson);

    Order order = modelMapper.map(element, Order.class);

    assertEquals(order.id, 456);
    assertEquals(order.customer.id, 789);
    assertEquals(order.customer.address.street, "123 Main Street");
    assertEquals(order.customer.address.city, "SF");

    String flatOrderJson = "{\"id\":222, \"customer_id\":333, \"customer_street_address\":\"444 Main Street\", \"customer_address_city\":\"LA\"}";
    element = jsonParser.parse(flatOrderJson);

    order = modelMapper.map(element, Order.class, "flat");

    assertEquals(order.id, 222);
    assertEquals(order.customer.id, 333);
View Full Code Here

    assertEquals(order.customer.address.city, "LA");
  }

  public void shouldMapWithExplicitMapping() throws Exception {
    String orderJson = "{\"id\":456, \"customer\":{\"id\":789, \"strt\":\"123 Main Street\", \"cty\":\"SF\"}}";
    JsonParser jsonParser = new JsonParser();
    JsonElement element = jsonParser.parse(orderJson);

    modelMapper.createTypeMap(element, Order.class).addMappings(
        new PropertyMap<JsonElement, Order>() {
          @Override
          protected void configure() {
View Full Code Here

    assertEquals(order.customer.address.city, "SF");
  }

  public void shouldGetElements() {
    String json = "{\"object\":{\"subkey\":\"subvalue\"}, \"array\":[\"elem1\", \"elem2\"], \"boolean\":true, \"number\":55, \"string\":\"foo\", \"null\": null}";
    JsonElement element = new JsonParser().parse(json);

    JsonObject objElem = (JsonObject) valueReader.get(element, "object");
    assertEquals(objElem.get("subkey").getAsString(), "subvalue");

    JsonArray arrayElem = (JsonArray) valueReader.get(element, "array");
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.