Package com.google.gson

Examples of com.google.gson.JsonObject.entrySet()


    public Metadata deserialize(JsonElement element, Type type,
            JsonDeserializationContext context) throws JsonParseException {

        final JsonObject obj = element.getAsJsonObject();
        Metadata m = new Metadata();
        for (Map.Entry<String, JsonElement> entry : obj.entrySet()){
            String key = entry.getKey();
            JsonElement v = entry.getValue();
            if (v.isJsonPrimitive()){
                m.set(key, v.getAsString());
            } else if (v.isJsonArray()){
View Full Code Here


     
      statsObj = new Gson().fromJson(json, Stats.class);

      //If user requested errors then add them in
      for (String fieldName: this.errorFields) {
        Set<Map.Entry<String, JsonElement>> elementSet = jsonObject.entrySet();
        Iterator<Map.Entry<String, JsonElement>> elementSetIt = elementSet.iterator();
        while (elementSetIt.hasNext()) {
          Map.Entry<String, JsonElement> nextElement = elementSetIt.next();
          String key = nextElement.getKey();
          if (key.matches(fieldName)) {
View Full Code Here

    public FormRepresentation decode(String code) throws FormEncodingException {
        FormRepresentation form = new FormRepresentation();
        JsonElement json = new JsonParser().parse(code);
        if (json.isJsonObject()) {
            JsonObject jsonObj = json.getAsJsonObject();
            if (jsonObj.entrySet().isEmpty()) {
                return null;
            }
            if (jsonObj.get("action") != null
                    && jsonObj.get("action").isJsonPrimitive()
                    && jsonObj.get("action").getAsJsonPrimitive().isString()) {
View Full Code Here

  public void beginObject()
    throws IOException
  {
    expect(JsonToken.BEGIN_OBJECT);
    JsonObject localJsonObject = (JsonObject)peekStack();
    this.stack.add(localJsonObject.entrySet().iterator());
  }

  public void endObject()
    throws IOException
  {
View Full Code Here

                // Higchart API for details
                if (value.getPlotOptions() != null) {
                    JsonObject plotOptionsJson = (JsonObject) tree
                            .remove("plotOptions");
                    if(plotOptionsJson != null) {
                        Set<Entry<String, JsonElement>> entrySet = plotOptionsJson
                                .entrySet();
                        for (Entry<String, JsonElement> entry : entrySet) {
                            tree.add(entry.getKey(), entry.getValue());
                        }
                        tree.addProperty("type", value.getPlotOptions()
View Full Code Here

                    series.addProperty("type", plotOptions.getChartType()
                            .toString());
                }
                JsonObject po = context.serialize(plotOptions)
                        .getAsJsonObject();
                Set<Entry<String, JsonElement>> entrySet = po.entrySet();
                for (Entry<String, JsonElement> entry : entrySet) {
                    series.add(entry.getKey(), entry.getValue());
                }
            }
            series.add("name", context.serialize(src.getName()));
View Full Code Here

    @Override
    public HeaderField deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
      JsonObject jsonObject = json.getAsJsonObject();
      Set<Map.Entry<String, JsonElement>> entrySet = jsonObject.entrySet();
      if (entrySet.size() != 1) {
        throw new JsonParseException("JSON Object has multiple entries: " + entrySet);
      }
      Map.Entry<String, JsonElement> entry = entrySet.iterator().next();
      String name = entry.getKey();
View Full Code Here

          typeName);
      return null;
    } catch (ClassNotFoundException e) {
      annotationType = UnknownAnnotation.class;

      for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
        if (TYPE_KEY.equals(entry.getKey())) {
          continue;
        }
        Object value;
        if (entry.getValue().isJsonObject() && entry.getValue().getAsJsonObject().has(TYPE_KEY)) {
View Full Code Here

      visitors.visit(writers.get(), e);
    } finally {
      closeContext();
    }
    obj = new JsonParser().parse(out.toString()).getAsJsonObject();
    assertEquals(2, obj.entrySet().size());
    assertTrue(obj.has("uuid"));
    assertTrue(obj.has("employeeNumber"));
    assertFalse(obj.has("writeOnlyProperty"));
  }
}
View Full Code Here

    JsonElement j1 = flatpack.getPacker().pack(FlatPackEntity.entity(e1));
    JsonElement j2 = flatpack.getPacker().pack(FlatPackEntity.entity(e2));

    JsonObject merged = FlatPackEntityMerge.merge(j2, j1).getAsJsonObject();

    assertEquals(2, merged.entrySet().size());
    assertEquals(e1.getUuid().toString(), merged.get("value").getAsString());
    JsonArray employeeArray = merged.get("data").getAsJsonObject().get("employee").getAsJsonArray();
    assertEquals(2, employeeArray.size());

    FlatPackEntity<Employee> entity =
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.