Package com.google.gson

Examples of com.google.gson.JsonArray


         }
         if (!src.getTargetTags().isEmpty()) {
            firewall.add("targetTags", buildArrayOfStrings(src.getTargetTags()));
         }
         if (!src.getAllowed().isEmpty()) {
            JsonArray rules = new JsonArray();
            for (Rule rule : src.getAllowed()) {
               rules.add(context.serialize(rule, Firewall.Rule.class));
            }
            firewall.add("allowed", rules);
         }
         return firewall;
      }
View Full Code Here


              JsonParseException {
         JsonObject rule = json.getAsJsonObject();
         Rule.Builder builder = Rule.builder();
         builder.IpProtocol(IpProtocol.fromValue(rule.get("IPProtocol").getAsString()));
         if (rule.get("ports") != null) {
            JsonArray ports = (JsonArray) rule.get("ports");
            for (JsonElement port : ports) {
               String portAsString = port.getAsString();
               if (portAsString.contains("-")) {
                  String[] split = portAsString.split("-");
                  builder.addPortRange(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
View Full Code Here

      @Override
      public JsonElement serialize(Firewall.Rule src, Type typeOfSrc, JsonSerializationContext context) {
         JsonObject ruleObject = new JsonObject();
         ruleObject.addProperty("IPProtocol", src.getIpProtocol().value());
         if (src.getPorts() != null && !src.getPorts().isEmpty()) {
            JsonArray ports = new JsonArray();
            for (Range<Integer> range : src.getPorts().asRanges()) {
               ports.add(new JsonPrimitive(range.lowerEndpoint() == range.upperEndpoint() ? range.lowerEndpoint() + "" :
                       range.lowerEndpoint() + "-" + range.upperEndpoint()));
            }
            ruleObject.add("ports", ports);
         }
         return ruleObject;
View Full Code Here

    if (jsonArray.size() == 2) {
      JsonObject cursor = jsonArray.get(0).getAsJsonObject();
      if (cursor != null) {
        list.setCursor(getGsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create().fromJson(cursor, PagedArrayList.Cursor.class));
      }
      JsonArray results = jsonArray.get(1).getAsJsonArray();
      for (JsonElement object : results) {
        E element = unmarshall(object);
        list.add(element);
      }
    }
View Full Code Here

  @Test
  public void testGetJSONArray() throws InvalidDDMSException {
    // Double
    List<Double> doubles = new ArrayList<Double>();
    doubles.add(Double.valueOf(1));
    JsonArray array = Util.getJSONArray(doubles);
    assertEquals(1, array.size());
   
    // String
    List<String> strings = new ArrayList<String>();
    strings.add("Test");
    strings.add("Dog");
    array = Util.getJSONArray(strings);
    assertEquals("Test", array.get(0).getAsString());
    assertEquals("Dog", array.get(1).getAsString());
   
    // AbstractBaseComponent
    List<Extent> components = new ArrayList<Extent>();
    components.add(new Extent("qualifier", "value"));
    array = Util.getJSONArray(components);
    assertEquals(1, array.size());
   
    // Unknown
    try {
      List<Long> unknowns = new ArrayList<Long>();
      unknowns.add(Long.valueOf(1));
View Full Code Here

    assertFalse(object.has("integer"));
    Util.addNonEmptyJsonProperty(object, "integer", Integer.valueOf(1));
    assertTrue(object.has("integer"));
   
    // JsonArray
    JsonArray array = new JsonArray();
    Util.addNonEmptyJsonProperty(object, "array", array);
    assertFalse(object.has("array"));
    array.add(new JsonPrimitive("test"));
    Util.addNonEmptyJsonProperty(object, "array", array);
    assertTrue(object.has("array"));
   
    // JsonObject
    Util.addNonEmptyJsonProperty(object, "object", (JsonObject) null);
View Full Code Here

    for (Map.Entry<FieldDescriptor, Object> fieldPair : fields.entrySet()) {
      final FieldDescriptor desc = fieldPair.getKey();
      if (desc.isRepeated()) {
        List<?> fieldList = (List<?>) fieldPair.getValue();
        if (fieldList.size() != 0) {
          JsonArray array = new JsonArray();
          for (Object o : fieldList) {
            array.add(serializeWithEnumRewrite(context, o));
          }
          ret.add(desc.getName(), array);
          }
        } else {
          ret.add(desc.getName(), serializeWithEnumRewrite(context, fieldPair.getValue()));
View Full Code Here

   *
   * @param values the values
   * @return a JSON array, with the values in the same order
   */
  public static JsonArray getJSONArray(List<?> values) {
    JsonArray array = new JsonArray();
    for (Iterator iterator = values.iterator(); iterator.hasNext();) {
      Object value = (Object) iterator.next();
      if (value instanceof Double) {
        array.add(new JsonPrimitive((Double) value));
      }
      else if (value instanceof String) {
        array.add(new JsonPrimitive((String) value));
      }
      else if (value instanceof AbstractBaseComponent) {
        array.add(((AbstractBaseComponent) value).getJSONObject());
      }
      else {
        throw new IllegalArgumentException("Unexpected class for JSON property: " + value);
      }
    }
View Full Code Here

    else if (value instanceof Integer) {
      Integer castValue = (Integer) value;
      object.addProperty(name, castValue);
    }
    else if (value instanceof JsonArray) {
      JsonArray castValue = (JsonArray) value;
      if (castValue.size() != 0)
        object.add(name, castValue);
    }
    else if (value instanceof JsonObject) {
      JsonObject castValue = (JsonObject) value;
      object.add(name, castValue);
View Full Code Here

    //Eva perez comparte una foto con uno de sus familiares.
    JsonObject familiar = familiars.get("data").getAsJsonArray().get(0).getAsJsonObject();   
    JsonObject message = new JsonObject();
    message.addProperty("body", "Cuerpo del mensaje");
    JsonArray tos = new JsonArray();
    JsonObject to = new JsonObject();
    to.addProperty("id", familiar.get("id").getAsLong());
    to.addProperty("firstName", familiar.get("firstName").getAsString());
    tos.add(to);
    message.add("receivers", tos);
    JsonArray contents = new JsonArray();
    JsonObject content = new JsonObject();
    content.addProperty("type", Content.ContentType.PHOTO.getName());
    content.addProperty("id", photo.id);
    content.addProperty("source", location);
    contents.add(content);
    message.add("contents", contents);
    request = newRequest();
    request.cookies.putAll(cookies);
    response = POST(request,"/api/me/outbox", "application/json", message.toString());
    assertStatus(StatusCode.OK,response);
View Full Code Here

TOP

Related Classes of com.google.gson.JsonArray

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.