Package com.google.gson

Examples of com.google.gson.JsonPrimitive


                               JsonSerializationContext context) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    JsonObject obj = new JsonObject();
    obj.add(JsonMatrixAdapter.CLASS, new JsonPrimitive(src.getClass().getName()));
    obj.add(VECTOR, new JsonPrimitive(gson.toJson(src)));
    return obj;
  }
View Full Code Here


  public static final String MATRIX = "matrix";

  public JsonElement serialize(Matrix src, Type typeOfSrc,
                               JsonSerializationContext context) {
    JsonObject obj = new JsonObject();
    obj.add(CLASS, new JsonPrimitive(src.getClass().getName()));
    obj.add(MATRIX, context.serialize(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 static class MatrixTypeAdapter
    implements JsonDeserializer<Matrix>, JsonSerializer<Matrix>, InstanceCreator<Matrix> {
    @Override
    public JsonElement serialize(Matrix m, Type type, JsonSerializationContext jsonSerializationContext) {
      JsonObject r = new JsonObject();
      r.add("rows", new JsonPrimitive(m.numRows()));
      r.add("cols", new JsonPrimitive(m.numCols()));
      JsonArray v = new JsonArray();
      for (int row = 0; row < m.numRows(); row++) {
        JsonArray rowData = new JsonArray();
        for (int col = 0; col < m.numCols(); col++) {
          rowData.add(new JsonPrimitive(m.get(row, col)));
        }
        v.add(rowData);
      }
      r.add("data", v);
      return r;
View Full Code Here

  public JsonElement serialize(Cluster 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

    @Override
    public JsonElement serialize(T x,
                                 Type type,
                                 JsonSerializationContext jsonSerializationContext) {
      JsonObject r = new JsonObject();
      r.add("class", new JsonPrimitive(x.getClass().getName()));
      r.add("value", jsonSerializationContext.serialize(x));
      return r;
    }
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)));
    // now, we add the state names
    if (outNames != null) {
      json.add(OUTNAMES, new JsonPrimitive(gson.toJson(outNames)));
    }
    if (hiddenNames != null) {
      json.add(HIDDENNAMES, new JsonPrimitive(gson.toJson(hiddenNames)));
    }
    // return the model to its original state :)
    model.hiddenStateNames = hiddenNames;
    model.outputStateNames = outNames;
    return json;
View Full Code Here

  private static class MatrixTypeAdapter
    implements JsonDeserializer<Matrix>, JsonSerializer<Matrix>, InstanceCreator<Matrix> {
    @Override
    public JsonElement serialize(Matrix m, Type type, JsonSerializationContext jsonSerializationContext) {
      JsonObject r = new JsonObject();
      r.add("rows", new JsonPrimitive(m.numRows()));
      r.add("cols", new JsonPrimitive(m.numCols()));
      JsonArray v = new JsonArray();
      for (int row = 0; row < m.numRows(); row++) {
        JsonArray rowData = new JsonArray();
        for (int col = 0; col < m.numCols(); col++) {
          rowData.add(new JsonPrimitive(m.get(row, col)));
        }
        v.add(rowData);
      }
      r.add("data", v);
      return r;
View Full Code Here

    @Override
    public JsonElement serialize(Vector m, Type type, JsonSerializationContext jsonSerializationContext) {
      JsonObject r = new JsonObject();
      JsonArray v = new JsonArray();
      for (int i = 0; i < m.size(); i++) {
        v.add(new JsonPrimitive(m.get(i)));
      }
      r.add("data", v);
      return r;
    }
View Full Code Here

    @Override
    public JsonElement serialize(State<AdaptiveLogisticRegression.Wrapper> state,
                                 Type type,
                                 JsonSerializationContext jsonSerializationContext) {
      JsonObject r = new JsonObject();
      r.add("id", new JsonPrimitive(state.getId()));
      JsonArray v = new JsonArray();
      for (double x : state.getParams()) {
        v.add(new JsonPrimitive(x));
      }
      r.add("params", v);

      v = new JsonArray();
      for (Mapping mapping : state.getMaps()) {
        v.add(jsonSerializationContext.serialize(mapping, Mapping.class));
      }
      r.add("maps", v);
      r.add("omni", new JsonPrimitive(state.getOmni()));
      r.add("step", jsonSerializationContext.serialize(state.getStep()));
      r.add("value", new JsonPrimitive(state.getValue()));
      r.add("payload", jsonSerializationContext.serialize(state.getPayload()));

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