Package com.google.gson

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


   * @return the n-dimensional point
   */
  public static Vector decodeVector(String formattedString) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    return gson.fromJson(formattedString, Vector.class);
  }

  public final int size() {
    return size; 
View Full Code Here


  }

  public String asFormatString() {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    return gson.toJson(this, Vector.class);
  }

  @Override
  public int hashCode() {
View Full Code Here

 
  @Override
  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 DirichletCluster deserialize(JsonElement json,
                                         Type typeOfT,
                                         JsonDeserializationContext context) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    JsonObject obj = json.getAsJsonObject();
    double total = obj.get("total").getAsDouble();
    String klass = obj.get("modelClass").getAsString();
    String modelJson = obj.get("modelJson").getAsString();
    ClassLoader ccl = Thread.currentThread().getContextClassLoader();
View Full Code Here

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

  @Override
  public int getId() {
View Full Code Here

  public static DirichletState getDirichletState(Configuration conf) {
    String statePath = conf.get(DirichletDriver.STATE_IN_KEY);
    String json = conf.get(DirichletDriver.MODEL_DISTRIBUTION_KEY);
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(ModelDistribution.class, new JsonModelDistributionAdapter());
    Gson gson = builder.create();
    ModelDistribution<VectorWritable> modelDistribution = gson.fromJson(json,
                                                                        AbstractVectorModelDistribution.MODEL_DISTRIBUTION_TYPE);
    String numClusters = conf.get(DirichletDriver.NUM_CLUSTERS_KEY);
    String alpha0 = conf.get(DirichletDriver.ALPHA_0_KEY);
View Full Code Here

   * @return The LogisticModelParameters object that we read.
   */
  public static LogisticModelParameters loadFrom(Reader in) {
    GsonBuilder gb = new GsonBuilder();
    gb.registerTypeAdapter(Matrix.class, new MatrixTypeAdapter());
    return gb.create().fromJson(in, LogisticModelParameters.class);
  }

  /**
   * Reads a model in JSON format from a File.
   *
 
View Full Code Here

 
  @Override
  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 Cluster deserialize(JsonElement json, Type typeOfT,
                              JsonDeserializationContext context) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    Gson gson = builder.create();
    JsonObject obj = json.getAsJsonObject();
    String klass = obj.get("class").getAsString();
    String model = obj.get("model").getAsString();
    ClassLoader ccl = Thread.currentThread().getContextClassLoader();
    Class<?> cl = null;
View Full Code Here

   * @return String containing the JSON of this model
   */
  public String toJson() {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(HmmModel.class, this);
    Gson gson = builder.create();
    return gson.toJson(this);
  }

  /**
   * Decode this HmmModel from a JSON string
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.