Package com.google.gson

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


                               JsonSerializationContext context) {
    // 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)));
    return json;
View Full Code Here


                                     JsonDeserializationContext context) throws JsonParseException {
    // 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();
    NaiveBayesModel model = gson.fromJson(modelString, NaiveBayesModel.class);
  
View Full Code Here

    GaussianClusterDistribution dist = new GaussianClusterDistribution(new VectorWritable(new DenseVector(2)));
    String json = dist.asJsonString();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(ModelDistribution.class, new JsonModelDistributionAdapter());
    builder.registerTypeAdapter(DistanceMeasure.class, new JsonDistanceMeasureAdapter());
    Gson gson = builder.create();
    GaussianClusterDistribution dist1 = (GaussianClusterDistribution) gson
        .fromJson(json, AbstractVectorModelDistribution.MODEL_DISTRIBUTION_TYPE);
    assertSame("prototype", dist.getModelPrototype().getClass(), dist1.getModelPrototype().getClass());
  }
View Full Code Here

        new DistanceMeasureClusterDistribution(new VectorWritable(new DenseVector(2)));
    String json = dist.asJsonString();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(ModelDistribution.class, new JsonModelDistributionAdapter());
    builder.registerTypeAdapter(DistanceMeasure.class, new JsonDistanceMeasureAdapter());
    Gson gson = builder.create();
    DistanceMeasureClusterDistribution dist1 = (DistanceMeasureClusterDistribution) gson
        .fromJson(json, AbstractVectorModelDistribution.MODEL_DISTRIBUTION_TYPE);
    assertSame("prototype", dist.getModelPrototype().getClass(), dist1.getModelPrototype().getClass());
    assertSame("measure", dist.getMeasure().getClass(), dist1.getMeasure().getClass());
  }
View Full Code Here

        new DistanceMeasureClusterDistribution(new VectorWritable(new DenseVector(2)), new EuclideanDistanceMeasure());
    String json = dist.asJsonString();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(ModelDistribution.class, new JsonModelDistributionAdapter());
    builder.registerTypeAdapter(DistanceMeasure.class, new JsonDistanceMeasureAdapter());
    Gson gson = builder.create();
    DistanceMeasureClusterDistribution dist1 = (DistanceMeasureClusterDistribution) gson
        .fromJson(json, AbstractVectorModelDistribution.MODEL_DISTRIBUTION_TYPE);
    assertSame("prototype", dist.getModelPrototype().getClass(), dist1.getModelPrototype().getClass());
    assertSame("measure", dist.getMeasure().getClass(), dist1.getMeasure().getClass());
  }
View Full Code Here

        ConsoleProxyStatus status = null;
        try {
            GsonBuilder gb = new GsonBuilder();
            gb.setVersion(1.3);
            Gson gson = gb.create();

            byte[] details = proxy.getSessionDetails();
            status = gson.fromJson(details != null ? new String(details, Charset.forName("US-ASCII")) : null, ConsoleProxyStatus.class);
        } catch (Throwable e) {
            s_logger.warn("Unable to parse proxy session details : " + Arrays.toString(proxy.getSessionDetails()));
View Full Code Here

        ConsoleProxyStatus status = null;
        try {
            GsonBuilder gb = new GsonBuilder();
            gb.setVersion(1.3);
            Gson gson = gb.create();
            status = gson.fromJson(answer.getDetails(), ConsoleProxyStatus.class);
        } catch (Throwable e) {
            s_logger.warn("Unable to parse load info from proxy, proxy vm id : " + answer.getProxyVmId() + ", info : " + answer.getDetails());
        }
View Full Code Here

            ConsoleProxyStatus status = null;
            try {
                GsonBuilder gb = new GsonBuilder();
                gb.setVersion(1.3);
                Gson gson = gb.create();
                status = gson.fromJson(cmd.getLoadInfo(), ConsoleProxyStatus.class);
            } catch (Throwable e) {
                s_logger.warn("Unable to parse load info from proxy, proxy vm id : " + cmd.getProxyVmId() + ", info : " + cmd.getLoadInfo());
            }
View Full Code Here

    if (gsonPretty == null) {
      GsonBuilder prettyBuilder = new GsonBuilder()
          .setPrettyPrinting()
          .excludeFieldsWithoutExposeAnnotation();
      GsonHelper.registerAdapters(prettyBuilder, registerAdapters());
      gsonPretty = prettyBuilder.create();
    }

    return gsonPretty;
  }
View Full Code Here

    gsonBuilder.registerTypeAdapter(UnregisterRequest.class, new TypeAdapterProtobuf());
    gsonBuilder.registerTypeAdapter(AuthenticateRequest.class, new TypeAdapterProtobuf());
    gsonBuilder.registerTypeAdapter(RevisionValue.class, new TypeAdapterProtobuf());
    gsonBuilder.registerTypeAdapter(ByteString.class, new TypeAdapterByteString());
    gsonBuilder.setPrettyPrinting();
    return gsonBuilder.create();
  }

  @SuppressWarnings("serial")
  public static class JsonConversionException extends Exception {
    JsonConversionException(String msg) {
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.