Package com.google.gson

Examples of com.google.gson.JsonArray


    assertTrue("El familiar interna se llama eva perez.", internal.get("username").getAsString().equals("eva.perez"));
   
    //Comprobacion: Juan Gomez comparte una foto con Eva perez
    JsonObject message = new JsonObject();
    message.addProperty("body", "Cuerpo del mensaje");
    JsonArray tos = new JsonArray();
    JsonObject to = new JsonObject();
    to.addProperty("id", internal.get("id").getAsNumber());
    to.addProperty("firstName", internal.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


    assertEquals(EventType.DOCUMENT_CHANGED, calledEvents.get(1));
    assertEquals(EventType.WAVELET_TAGS_CHANGED, calledEvents.get(2));

    // Assert that the outgoing operation bundle contains robot.notify() op.
    JsonParser jsonParser = new JsonParser();
    JsonArray ops = jsonParser.parse(mockWriter.getString()).getAsJsonArray();
    assertEquals(1, ops.size());

    JsonObject op = ops.get(0).getAsJsonObject();
    assertEquals(OperationType.ROBOT_NOTIFY_CAPABILITIES_HASH.method(),
        op.get(RequestProperty.METHOD.key()).getAsString());

    JsonObject params = op.get(RequestProperty.PARAMS.key()).getAsJsonObject();
    assertEquals("0.21", params.get(ParamsProperty.PROTOCOL_VERSION.key()).getAsString());
View Full Code Here

    @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

      return r;
    }
  }

  public static double[] asArray(JsonObject v, String name) {
    JsonArray x = v.get(name).getAsJsonArray();
    double[] params = new double[x.size()];
    int i = 0;
    for (JsonElement element : x) {
      params[i++] = element.getAsDouble();
    }
    return params;
View Full Code Here

      JsonObject x = jsonElement.getAsJsonObject();
      r.setRecord(x.get("record").getAsInt());
      r.setAucEvaluator(jsonDeserializationContext.<OnlineAuc>deserialize(x.get("auc"), OnlineAuc.class));
      r.setLogLikelihood(x.get("logLikelihood").getAsDouble());

      JsonArray models = x.get("models").getAsJsonArray();
      for (JsonElement model : models) {
        r.addModel(
            jsonDeserializationContext.<OnlineLogisticRegression>deserialize(model, OnlineLogisticRegression.class));
      }
View Full Code Here

    @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

  private static class VectorTypeAdapter
    implements JsonDeserializer<Vector>, JsonSerializer<Vector>, InstanceCreator<Vector> {
    @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

      return r;
    }

    @Override
    public Vector deserialize(JsonElement x, Type type, JsonDeserializationContext jsonDeserializationContext) {
      JsonArray data = x.getAsJsonObject().get("data").getAsJsonArray();
      Vector r = new DenseVector(data.size());
      int i = 0;
      for (JsonElement v : data) {
        r.set(i, v.getAsDouble());
        i++;
      }
View Full Code Here

    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()));
View Full Code Here

    public JsonElement serialize(EvolutionaryProcess<AdaptiveLogisticRegression.Wrapper> x,
                                 Type type,
                                 JsonSerializationContext jsc) {
      JsonObject r = new JsonObject();
      r.add("threadCount", new JsonPrimitive(x.getThreadCount()));
      JsonArray v = new JsonArray();
      for (State<AdaptiveLogisticRegression.Wrapper> state : x.getPopulation()) {
        v.add(jsc.serialize(state, STATE_TYPE));
      }
      r.add("population", v);
      return r;
    }
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.