Package com.google.gson

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


     * @return
     */
    public static String getJsonStringForDate(Object object, Integer dateFormat) {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat(dateFormat);
        Gson gson = gsonBuilder.create();
        return gson.toJson(object);
    }
   
    /**
     * Returns the JSON representation of the given object and the date format.
View Full Code Here


     * @return
     */
    public static String getJsonStringForDate(Object object, String dateFormat) {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat(dateFormat);
        Gson gson = gsonBuilder.create();
        return gson.toJson(object);
    }


    /**
 
View Full Code Here

     * @return
     */
    public static String getJsonStringForDateAndTime(Object object, Integer dateFormat, Integer timeFormat) {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat(dateFormat, timeFormat);
        Gson gson = gsonBuilder.create();
        return gson.toJson(object);
    }

    /**
     * Returns the JSON representation of the given Key and Value.
View Full Code Here

     * @return
     */
    public static String getJsonStringWithNullFieldsIncluded(Object object) {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.serializeNulls();
        Gson gson = gsonBuilder.create();
        return gson.toJson(object);
    }

    /**
     * Returns the JSON representation to populate the form.
View Full Code Here

     * @return
     */
    public static String getJsonFormString(Object object) {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.serializeNulls();
        Gson gson = gsonBuilder.create();
        //IPolCoreFormBean polCoreFormBean = (IPolCoreFormBean) object;
        //List<ValidationError> errors = polCoreFormBean.getErrors();
        //if (errors.isEmpty()) {
            return "{success:true,data:" + gson.toJson(object) + "}";
        //}
View Full Code Here

     * @return
     */
    public static Object getJavaFormJSON(String json, Object obj) {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.serializeNulls();
        Gson gson = gsonBuilder.create();
        return gson.fromJson(json, obj.getClass());
    }

}
View Full Code Here

  public String toJSON() {
    GsonBuilder builder = new GsonBuilder();
    if (Boolean.valueOf(PropertyReader.getProperty("output.json.prettyPrint"))) {
      builder.setPrettyPrinting();
    }
    return (builder.create().toJson(getJSONObject()));
  }
 
  /**
   * @see IDDMSComponent#toText()
   */
 
View Full Code Here

  public JsonElement serialize(Vector 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(JsonMatrixAdapter.CLASS, new JsonPrimitive(src.getClass().getName()));
    obj.add(VECTOR, new JsonPrimitive(gson.toJson(src)));
    return obj;
  }
View Full Code Here

  public Vector 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(JsonMatrixAdapter.CLASS).getAsString();
    String vector = obj.get(VECTOR).getAsString();
    ClassLoader ccl = Thread.currentThread().getContextClassLoader();
    Class<?> cl;
View Full Code Here

  static Gson gson() {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(VectorList.class, new VectorList.JsonVectorListAdapter());
    builder.registerTypeAdapter(Vector.class, new JsonVectorAdapter());
    builder.registerTypeAdapter(Matrix.class, new JsonMatrixAdapter());
    Gson gson = builder.create();
    return gson;
  }

  public Matrix assign(double value) {
    int[] c = size();
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.