Examples of registerTypeAdapter()


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

  private static final Logger log = LoggerFactory.getLogger(JsonModelAdapter.class);
 
  @Override
  public JsonElement serialize(Model<?> 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

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

 
  @Override
  public Model<?> 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();
View Full Code Here

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

  private static final Logger log = LoggerFactory.getLogger(JsonDistanceMeasureAdapter.class);

  @Override
  public JsonElement serialize(DistanceMeasure 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

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

  }

  @Override
  public DistanceMeasure 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();
View Full Code Here

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

  public abstract String getIdentifier();

  @Override
  public String asJsonString() {
    GsonBuilder gBuilder = new GsonBuilder();
    gBuilder.registerTypeAdapter(VECTOR_TYPE, new JsonVectorAdapter());
    Gson gson = gBuilder.create();
    return gson.toJson(this, this.getClass());
  }

  @Override
View Full Code Here

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

  }

  @Override
  public String asFormatString() {
    GsonBuilder gBuilder = new GsonBuilder();
    gBuilder.registerTypeAdapter(VECTOR_TYPE, new JsonVectorAdapter());
    Gson gson = gBuilder.create();
    return gson.toJson(this, MeanShiftCanopy.class);
  }

  public void setBoundPoints(IntArrayList boundPoints) {
View Full Code Here

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

    Cluster model = new NormalModel(5, 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, MODEL_TYPE);
    assertEquals("Json", format, model2.asFormatString(null));
  }
View Full Code Here

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

    Cluster model = new SampledNormalModel(5, 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, MODEL_TYPE);
    assertEquals("Json", format, model2.asFormatString(null));
  }
View Full Code Here

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

    Cluster model = new AsymmetricSampledNormalModel(5, m, m);
    String format = model.asFormatString(null);
    assertEquals("format", "asnm{n=0 m=[1.100, 2.200, 3.300] sd=[1.100, 2.200, 3.300]}", format);
    String json = model.asJsonString();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    AsymmetricSampledNormalModel model2 = gson.fromJson(json, MODEL_TYPE);
    assertEquals("Json", format, model2.asFormatString(null));
  }
View Full Code Here

Examples of com.google.wave.api.impl.GsonFactory.registerTypeAdapter()

    // Remove lines below if we want to stop support for <0.22
    gsons.put(ProtocolVersion.V2_1, gsonForPostV2);

    GsonFactory factoryForV2 = new GsonFactory();
    ElementGsonAdaptorV2 elementGsonAdaptorV2 = new ElementGsonAdaptorV2();
    factoryForV2.registerTypeAdapter(Element.class, elementGsonAdaptorV2);
    factoryForV2.registerTypeAdapter(Attachment.class, elementGsonAdaptorV2);
    gsons.put(ProtocolVersion.V2, factoryForV2.create());

    return new RobotSerializer(gsons, ProtocolVersion.DEFAULT);
  }
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.