Package com.google.gson

Examples of com.google.gson.GsonBuilder.create()


   * @return Initialized model
   */
  public static HmmModel fromJson(String json) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(HmmModel.class, new HmmModel());
    Gson gson = builder.create();
    return gson.fromJson(json, HmmModel.class);
  }

  // CODE USED FOR SERIALIZATION

View Full Code Here


                              JsonDeserializationContext context) {
    // register the builders for matrix / vector
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Matrix.class, new JsonMatrixAdapter());
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    // now decode the original model
    JsonObject obj = json.getAsJsonObject();
    String modelString = obj.get(MODEL).getAsString();
    HmmModel model = gson.fromJson(modelString, HmmModel.class);
    // now decode the names
View Full Code Here

    model.outputStateNames = null;
    // now register the builders for matrix / vector
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Matrix.class, new JsonMatrixAdapter());
    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
View Full Code Here

  @Override
  public String asJsonString() {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    return gson.toJson(this, MODEL_TYPE);
  }

  @Override
  public Vector getCenter() {
View Full Code Here

  @Override
  public String asJsonString() {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    return gson.toJson(this, MODEL_TYPE);
  }

  @Override
  public Vector getCenter() {
View Full Code Here

  @Override
  public String asJsonString() {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    return gson.toJson(this, MODEL_TYPE);
  }

  @Override
  public Vector getCenter() {
View Full Code Here

  @Override
  public String asJsonString() {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(ModelDistribution.class, new JsonModelDistributionAdapter());
    builder.registerTypeAdapter(DistanceMeasure.class, new JsonDistanceMeasureAdapter());
    Gson gson = builder.create();
    return gson.toJson(this, MODEL_DISTRIBUTION_TYPE);
  }

  /**
   * @return the modelPrototype
View Full Code Here

        new LocationModelMarshal())
      .registerTypeAdapter(PolygonLocationModel.class,
        new LocationModelMarshal());

    builder.setPrettyPrinting();
    Gson gson = builder.create();
    String s = gson.toJson(mc, ModelContainer.class);
    out.write(s.getBytes("UTF-8"));
    out.close();
  }
View Full Code Here

  ) {
    GsonBuilder builder = new GsonBuilder()
    .registerTypeAdapter(LocationModel.class,
      new LocationModelMarshal());

    Gson gson = builder.create();
    return gson.fromJson(json, ModelContainer.class);
  }

  public static ModelContainer modelContainerFromFile(
    final String path
View Full Code Here

      for (TypeAdapterFactory factory : bindings.getFactories()) {
         builder.registerTypeAdapterFactory(factory);
      }

      return builder.create();
   }

   @ImplementedBy(NoExclusions.class)
   public static interface DefaultExclusionStrategy extends ExclusionStrategy {
   }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.