Package com.google.gson

Examples of com.google.gson.GsonBuilder


  }
 
  @Override
  public Model<?> deserialize(JsonElement json, Type typeOfT,
                              JsonDeserializationContext context) throws JsonParseException {
    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


    VectorWritable.writeVector(out, s2);
  }
 
  @Override
  public String asJsonString() {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    return gson.toJson(this, modelType);
  }
View Full Code Here

    return model.toString();
  }
 
  @Override
  public String asJsonString() {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    return gson.toJson(this, clusterType);
  }
View Full Code Here

   *
   * @see org.apache.mahout.clustering.Printable#asJsonString()
   */
  @Override
  public String asJsonString() {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Model.class, new JsonModelAdapter());
    Gson gson = builder.create();
    return gson.toJson(this, modelType);
  }
View Full Code Here

        public Map<Integer, Integer> mapField = null;
    }
   

    public static void main(String[] args) throws Exception {
        Gson gson = new GsonBuilder().create();

        String quotes = "{\"mapField\": {\"5\": \"6\", \"7\": \"8\"}}";
        String keyQuotes = "{\"mapField\": {\"5\": 6, \"7\": 8}}";
        String noQuotes = "{\"mapField\": {5: 6, 7: 8}}";
View Full Code Here

        }
    }

    /** Get a properly configured Gson object for use in other methods. */
    private static Gson getGson() {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.registerTypeAdapter(Date.class, new GsonDateSerializer());
        return gsonBuilder.create();
    }
View Full Code Here

        .initParam("com.sun.jersey.api.json.POJOMappingFeature", "true")
        .build());
  }

  public static <T> T getJsonFormString(String json, Class<T> type) {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.serializeNulls();
    Gson gson = gsonBuilder.create();
    return (T) gson.fromJson(json, type);
  }
View Full Code Here

    }

    private static String string(final Object out, final String lineSep) {
        if (!out.getClass().getName().startsWith("java")) {
            try {
                return new GsonBuilder().setPrettyPrinting().create().toJson(out)
                            .replace(OS_LINE_SEP, lineSep);
            } catch (RuntimeException re) {
                return ToStringBuilder.reflectionToString(out, ToStringStyle.SHORT_PREFIX_STYLE)
                            .replace(OS_LINE_SEP, lineSep);
            }
View Full Code Here

    desc.isAscending = isAscending;
    return desc;
  }
 
  public String toString() {
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    return gson.toJson(this);
  }
View Full Code Here

    return gson;
  }

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

    return gsonPretty;
  }
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.