Package com.google.gson

Examples of com.google.gson.JsonPrimitive


    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    builder.registerTypeAdapter(matrixType, new JsonMatrixAdapter());
    Gson gson = builder.create();
    JsonObject obj = new JsonObject();
    obj.add(CLASS, new JsonPrimitive(src.getClass().getName()));
    obj.add(MATRIX, new JsonPrimitive(gson.toJson(src)));
    return obj;
  }
View Full Code Here


  public JsonElement serialize(DirichletCluster<?> 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("total", new JsonPrimitive(src.getTotalCount()));
    obj.add("modelClass", new JsonPrimitive(src.getModel().getClass().getName()));
    obj.add("modelJson", 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

    private static class GsonDateSerializer implements JsonSerializer<Date>, JsonDeserializer<Date> {
        private String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS Z";

        @Override
        public JsonElement serialize(Date date, Type typeOfT, JsonSerializationContext context) {
            return new JsonPrimitive(DateUtils.formatDate(date, DATE_FORMAT));
        }
View Full Code Here

   }

   private static JsonArray buildArrayOfStrings(Set<String> strings) {
      JsonArray array = new JsonArray();
      for (String string : strings) {
         array.add(new JsonPrimitive(string));
      }
      return array;
   }
View Full Code Here

      }

      @Override
      public JsonElement serialize(Metadata src, Type typeOfSrc, JsonSerializationContext context) {
         JsonObject metadataObject = new JsonObject();
         metadataObject.add("kind", new JsonPrimitive("compute#metadata"));
         JsonArray items = new JsonArray();
         for (Map.Entry<String, String> entry : src.entrySet()) {
            JsonObject object = new JsonObject();
            object.addProperty("key", entry.getKey());
            object.addProperty("value", entry.getValue());
View Full Code Here

         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

    JsonElement toJson() {
        JsonObject root = new JsonObject();

        addCommonFields(root);

        root.add("trueLabel", new JsonPrimitive(this.trueDisplayValue));
        root.add("falseLabel", new JsonPrimitive(this.falseDisplayValue));

        return root;
    }
View Full Code Here

                StringWriter sw = new StringWriter();
                JSONJAXBContext.getJSONMarshaller(marshaller).marshallToJSON(obj, sw);
                array.add(parser.parse(sw.toString()));
            }
            catch(JAXBException e) {
                array.add(new JsonPrimitive(obj.toString()));
            }
        }
        out.write(new Gson().toJson(array).getBytes());
    }
View Full Code Here

        addCommonFields(root);

        JsonObject ranges = new JsonObject();
        // In Splunk 6.0.1.1, data models incorrectly expect strings for these fields
        // instead of numbers. In 6.1, this is fixed and both are accepted.
        if (start != null) ranges.add("start", new JsonPrimitive(start.toString()));
        if (end != null) ranges.add("end", new JsonPrimitive(end.toString()));
        if (step != null) ranges.add("size", new JsonPrimitive(step.toString()));
        if (limit != null) ranges.add("maxNumberOf", new JsonPrimitive(limit.toString()));
        root.add("ranges", ranges);
        root.add("display", new JsonPrimitive("ranges"));

        return root;
    }
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.