Package com.google.gson

Examples of com.google.gson.GsonBuilder


    test.setLabelBindings(bindings);

    Type vectorType = new TypeToken<Vector>() {
    }.getType();

    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    Gson gson = builder.create();
    String json = gson.toJson(test, vectorType);
    Vector test1 = gson.fromJson(json, vectorType);
    try {
      test1.get("Fee");
      fail();
View Full Code Here


    test.setLabelBindings(bindings);

    Type vectorType = new TypeToken<Vector>() {
    }.getType();

    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    Gson gson = builder.create();
    String json = gson.toJson(test, vectorType);
    Vector test1 = gson.fromJson(json, vectorType);
    try {
      test1.get("Fee");
      fail();
View Full Code Here

                               JsonSerializationContext context) {
    Type vectorType = new TypeToken<Vector>() {
    }.getType();
    Type matrixType = new TypeToken<Matrix>() {
    }.getType();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    builder.registerTypeAdapter(matrixType, new JsonMatrixAdapter());
    Gson gson = builder.create();
    JsonObject obj = new JsonObject();
    obj.add(CLASS, new JsonPrimitive(src.getClass().getName()));
    obj.add(MATRIX, new JsonPrimitive(gson.toJson(src)));
    return obj;
  }
View Full Code Here

                            JsonDeserializationContext context) throws JsonParseException {
    Type vectorType = new TypeToken<Vector>() {
    }.getType();
    Type matrixType = new TypeToken<Matrix>() {
    }.getType();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    builder.registerTypeAdapter(matrixType, new JsonMatrixAdapter());
    Gson gson = builder.create();
    JsonObject obj = json.getAsJsonObject();
    String klass = obj.get(CLASS).getAsString();
    String matrix = obj.get(MATRIX).getAsString();
    ClassLoader ccl = Thread.currentThread().getContextClassLoader();
    Class<?> cl = null;
View Full Code Here

  public static Matrix decodeMatrix(String formatString) {
    Type vectorType = new TypeToken<Vector>() {
    }.getType();
    Type matrixType = new TypeToken<Matrix>() {
    }.getType();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    builder.registerTypeAdapter(matrixType, new JsonMatrixAdapter());
    Gson gson = builder.create();
    return gson.fromJson(formatString, matrixType);
  }
View Full Code Here

  public String asFormatString() {
    Type vectorType = new TypeToken<Vector>() {
    }.getType();
    Type matrixType = new TypeToken<Matrix>() {
    }.getType();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    builder.registerTypeAdapter(matrixType, new JsonMatrixAdapter());
    Gson gson = builder.create();
    return gson.toJson(this, matrixType);
  }
View Full Code Here

    Vector m = new DenseVector(d);
    Printable model = new NormalModel(m, 0.75);
    String format = model.asFormatString(null);
    assertEquals("format", "nm{n=0 m=[1.100, 2.200, 3.300] sd=0.75}", format);
    String json = model.asJsonString();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    NormalModel model2 = gson.fromJson(json, modelType);
    assertEquals("Json", format, model2.asFormatString(null));
  }
View Full Code Here

   * @return the n-dimensional point
   */
  public static Vector decodeVector(String formattedString) {
    Type vectorType = new TypeToken<Vector>() {
    }.getType();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    Gson gson = builder.create();
    return gson.fromJson(formattedString, vectorType);
  }
View Full Code Here

  }

  public String asFormatString() {
    Type vectorType = new TypeToken<Vector>() {
    }.getType();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(vectorType, new JsonVectorAdapter());
    Gson gson = builder.create();
    return gson.toJson(this, vectorType);
  }
View Full Code Here

    Vector m = new DenseVector(d);
    Printable model = new SampledNormalModel(m, 0.75);
    String format = model.asFormatString(null);
    assertEquals("format", "snm{n=0 m=[1.100, 2.200, 3.300] sd=0.75}", format);
    String json = model.asJsonString();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    SampledNormalModel model2 = gson.fromJson(json, modelType);
    assertEquals("Json", format, model2.asFormatString(null));
  }
View Full Code Here

TOP

Related Classes of com.google.gson.GsonBuilder

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.