Examples of JSONStringer


Examples of com.oltpbenchmark.util.json.JSONStringer

     * @param <T>
     * @param object
     * @return
     */
    public static <T extends JSONSerializable> String format(T object) {
        JSONStringer stringer = new JSONStringer();
        try {
            if (object instanceof JSONObject) return ((JSONObject)object).toString(2);
            stringer.object();
            object.toJSON(stringer);
            stringer.endObject();
        } catch (JSONException ex) {
            throw new RuntimeException(ex);
        }
        return (JSONUtil.format(stringer.toString()));
    }
View Full Code Here

Examples of com.oltpbenchmark.util.json.JSONStringer

     * @param <T>
     * @param object
     * @return
     */
    public static String toJSONString(Object object) {
        JSONStringer stringer = new JSONStringer();
        try {
            if (object instanceof JSONSerializable) {
                stringer.object();
                ((JSONSerializable)object).toJSON(stringer);
                stringer.endObject();
            } else if (object != null) {
                Class<?> clazz = object.getClass();
//                stringer.key(clazz.getSimpleName());
                JSONUtil.writeFieldValue(stringer, clazz, object);
            }
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
        return (stringer.toString());
    }
View Full Code Here

Examples of net.sf.json.util.JSONStringer

   * @return
   */
  public ViewResults adhoc(final AdHocView view) {


    String adHocBody = new JSONStringer()
        .object()
          .key("map").value(JSONUtils.stringSerializedFunction(view.getFunction()))
        .endObject()
        .toString();
   
View Full Code Here

Examples of org.amplafi.json.JSONStringer

    }

    @Test
    public void testNullFiltering() {
        MapJsonRenderer renderer = new MapJsonRenderer(false);
        JSONStringer jsonWriter = new JSONStringer();
        jsonWriter.addRenderer(renderer);
        Map<String, Object> map = new LinkedHashMap<String, Object>();
        map.put(null, "gg");
        map.put("ff", null);
        jsonWriter.value(map);
        assertEquals(jsonWriter.toString(), "{}");
    }
View Full Code Here

Examples of org.apache.wicket.ajax.json.JSONStringer

  private Boolean selectOnBlur;
  private Boolean dropdownAutoWidth;

  public CharSequence toJson() {
    try {
      JSONStringer writer = new JSONStringer();
      writer.object();
      Json.writeObject(writer, "minimumInputLength", minimumInputLength);
      Json.writeObject(writer, "minimumResultsForSearch", minimumResultsForSearch);
      Json.writeObject(writer, "maximumSelectionSize", maximumSelectionSize);
      Json.writeObject(writer, "placeholder", placeholder);
      Json.writeObject(writer, "allowClear", allowClear);
      Json.writeObject(writer, "multiple", multiple);
      Json.writeObject(writer, "closeOnSelect", closeOnSelect);
      Json.writeFunction(writer, "id", id);
      Json.writeFunction(writer, "matcher", matcher);
      Json.writeFunction(writer, "tokenizer", tokenizer);
      Json.writeFunction(writer, "sortResults", sortResults);
      Json.writeFunction(writer, "formatSelection", formatSelection);
      Json.writeFunction(writer, "formatResult", formatResult);
      Json.writeFunction(writer, "formatNoMatches", formatNoMatches);
      Json.writeFunction(writer, "formatInputTooShort", formatInputTooShort);
      Json.writeFunction(writer, "formatResultCssClass", formatResultCssClass);
      Json.writeFunction(writer, "formatSelectionTooBig", formatSelectionTooBig);
      Json.writeFunction(writer, "formatLoadMore", formatLoadMore);
      Json.writeFunction(writer, "formatSearching", formatSearching);
      Json.writeFunction(writer, "escapeMarkup", escapeMarkup);
      Json.writeFunction(writer, "createSearchChoice", createSearchChoice);
      Json.writeFunction(writer, "initSelection", initSelection);
      Json.writeFunction(writer, "query", query);
      Json.writeObject(writer, "width", width);
      Json.writeObject(writer, "openOnEnter", openOnEnter);
      Json.writeFunction(writer, "containerCss", containerCss);
      Json.writeObject(writer, "containerCssClass", containerCssClass);
      Json.writeFunction(writer, "dropdownCss", dropdownCss);
      Json.writeObject(writer, "dropdownCssClass", dropdownCssClass);
      Json.writeObject(writer, "separator", separator);
      Json.writeObject(writer, "tokenSeparators", tokenSeparators);
      Json.writeObject(writer, "selectOnBlur", selectOnBlur);
      Json.writeObject(writer, "dropdownAutoWidth", dropdownAutoWidth);
      if (ajax != null) {
        writer.key("ajax");
        ajax.toJson(writer);
      }
      Json.writeFunction(writer, "data", data);
      Json.writeFunction(writer, "tags", tags);
      writer.endObject();

      return writer.toString();
    } catch (JSONException e) {
      throw new RuntimeException("Could not convert Select2 settings object to Json", e);
    }
  }
View Full Code Here

Examples of org.apache.wink.json4j.JSONStringer

    /**
     * Test the contructor.
     */
    public void test_new() {
        JSONStringer jStringer = new JSONStringer();
    }
View Full Code Here

Examples of org.apache.wink.json4j.compat.JSONStringer

     * Test the contructor.
     */
    public void test_new() {
        System.setProperty("org.apache.wink.common.model.json.factory.impl", "org.apache.wink.json4j.compat.impl.ApacheJSONFactory");
        JSONFactory factory = JSONFactory.newInstance();
        JSONStringer jStringer = factory.createJSONStringer();
    }
View Full Code Here

Examples of org.apache.wink.json4j.compat.JSONStringer

    public void test_WriteEmptyObject() {
        Exception ex = null;
        try{
            System.setProperty("org.apache.wink.common.model.json.factory.impl", "org.apache.wink.json4j.compat.impl.ApacheJSONFactory");
            JSONFactory factory = JSONFactory.newInstance();
            JSONStringer jStringer = factory.createJSONStringer();
            jStringer.object();
            jStringer.endObject();
            String str = jStringer.toString();
            // Verify it parses.
            JSONObject test = factory.createJSONObject(str);
            assertTrue(str.equals("{}"));
        }catch(Exception ex1){
            ex = ex1;
View Full Code Here

Examples of org.apache.wink.json4j.compat.JSONStringer

    public void test_WriteEmptyObjectClose() {
        Exception ex = null;
        try{
            System.setProperty("org.apache.wink.common.model.json.factory.impl", "org.apache.wink.json4j.compat.impl.ApacheJSONFactory");
            JSONFactory factory = JSONFactory.newInstance();
            JSONStringer jStringer = factory.createJSONStringer();
            jStringer.object();
            jStringer.close();
            String str = jStringer.toString();
            System.out.println("STRING: " + str);
            // Verify it parses.
            JSONObject test = factory.createJSONObject(str);
            assertTrue(str.equals("{}"));
        }catch(Exception ex1){
View Full Code Here

Examples of org.apache.wink.json4j.compat.JSONStringer

    public void test_WriteEmptyArray() {
        Exception ex = null;
        try{
            System.setProperty("org.apache.wink.common.model.json.factory.impl", "org.apache.wink.json4j.compat.impl.ApacheJSONFactory");
            JSONFactory factory = JSONFactory.newInstance();
            JSONStringer jStringer = factory.createJSONStringer();
            jStringer.array();
            jStringer.endArray();
            String str = jStringer.toString();
            // Verify it parses.
            JSONArray test = factory.createJSONArray(str);
            assertTrue(str.equals("[]"));
        }catch(Exception ex1){
            ex = ex1;
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.