Package com.google.gson

Examples of com.google.gson.JsonPrimitive


         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


    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    builder.registerTypeAdapter(DistanceMeasure.class, new JsonDistanceMeasureAdapter());
    Gson gson = builder.create();
    JsonObject obj = new JsonObject();
    obj.add("class", new JsonPrimitive(src.getClass().getName()));
    obj.add("model", new JsonPrimitive(gson.toJson(src)));
    return obj;
  }
View Full Code Here

  public JsonElement serialize(Model<?> src, Type typeOfSrc, JsonSerializationContext context) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    JsonObject obj = new JsonObject();
    obj.add("class", new JsonPrimitive(src.getClass().getName()));
    obj.add("model", new JsonPrimitive(gson.toJson(src)));
    return obj;
  }
View Full Code Here

  public JsonElement serialize(DistanceMeasure src, Type typeOfSrc, JsonSerializationContext context) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    JsonObject obj = new JsonObject();
    obj.add("class", new JsonPrimitive(src.getClass().getName()));
    obj.add("model", new JsonPrimitive(gson.toJson(src)));
    return obj;
  }
View Full Code Here

    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    // create a model
    JsonObject json = new JsonObject();
    // first, we add the model
    json.add(MODEL, new JsonPrimitive(gson.toJson(model)));
    return json;
  }
View Full Code Here

      return deserialize(json, type, context);
    }

    @Override
    public JsonElement serialize(Text text, Type type, JsonSerializationContext context) {
      return new JsonPrimitive(text.getValue());
    }
View Full Code Here

      return deserialize(json, type, context);
    }

    @Override
    public JsonElement serialize(Blob blob, Type type, JsonSerializationContext context) {
      return new JsonPrimitive(Base64.encode(blob.getBytes()));
    }
View Full Code Here

   
    // 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

  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 {
View Full Code Here

        }}).registerTypeAdapter(java.util.Date.class, new
        JsonSerializer<java.util.Date>() {
      @Override
      public JsonElement serialize(java.util.Date src, Type typeOfSrc,
          com.google.gson.JsonSerializationContext context) {
        return new JsonPrimitive(src.getTime());
      }
    }).create();
    return gson;
  }
View Full Code Here

TOP

Related Classes of com.google.gson.JsonPrimitive

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.