Package org.json

Examples of org.json.JSONStringer


    private static QName _name = new QName("", "name");

    private static final QName c_body = new QName("c", XProcConstants.NS_XPROC_STEP, "body");

    public static String convert(XdmNode json) {
        JSONStringer js = new JSONStringer();

        json = S9apiUtils.getDocumentElement(json);

        if (c_body.equals(json.getNodeName())) {
            XdmNode jchild = null;
            XdmSequenceIterator iter = json.axisIterator(Axis.CHILD);
            while (iter.hasNext()) {
                XdmItem item = iter.next();
                if (item instanceof XdmNode) {
                    XdmNode child = (XdmNode) item;
                    if (child.getNodeKind() == XdmNodeKind.ELEMENT) {
                        if (jchild != null) {
                            throw new XProcException("Found c:body containing more than one JSON element?");
                        } else {
                            jchild = child;
                        }
                    }
                }
            }
            json = jchild;
        }

        try {
            build(json, js, ROOT);
        } catch (JSONException jse) {
            throw new XProcException(jse);
        }

        return js.toString();
    }
View Full Code Here


    private String[] tokenSeparators;
    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, "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

  }

  public static String createRequest()
  throws JSONException {
    float epoch = System.currentTimeMillis()/1000;
    JSONStringer msg = new JSONStringer();
    return msg
            .object()
            .key("client_name")
            .value("RPC Client 1.0")
            .key("time")
            .value(Float.toString(epoch))
View Full Code Here

            prototype.name().set( name );
            prototype.entityType().set( first(Qi4j.FUNCTION_DESCRIPTOR_FOR.map( entity ).types()).getName() );
            prototype.entityId().set( entity.identity().get() );

            // JSON-ify parameters
            JSONStringer json = new JSONStringer();
            try
            {
                JSONWriter params = json.object();
                for (int i = 0; i < args.length; i++)
                {
                    params.key( "param" + i );
                    if (args[i] == null)
                        params.value( JSONObject.NULL );
                    else
                        params.value( args[i] );
                }
                json.endObject();
            } catch (JSONException e)
            {
                throw new IllegalArgumentException( "Could not create eventValue", e );
            }

            prototype.parameters().set( json.toString() );

            DomainEventValue eventValue = builder.newInstance();

            return eventValue;
        }
View Full Code Here

            UnitOfWork uow = uowf.currentUnitOfWork();
            prototype.usecase().set( uow.usecase().name() );
            prototype.version().set( version );

            // JSON-ify parameters
            JSONStringer json = new JSONStringer();
            try
            {
                JSONWriter params = json.object();
                for (int i = 1; i < args.length; i++)
                {
                    params.key( "param" + i );
                    if (args[i] == null)
                        params.value( JSONObject.NULL );
                    else
                        params.value( args[i] );
                }
                json.endObject();
            } catch (JSONException e)
            {
                throw new IllegalArgumentException( "Could not create event", e );
            }

            prototype.parameters().set( json.toString() );

            ApplicationEvent event = builder.newInstance();

            return event;
        }
View Full Code Here

*
*/
public final class JSONUtils {

    public static String buildJSON(Map<String, Object> params) throws JSONException {
        final JSONStringer stringer = new JSONStringer();
        stringer.object();

        for (Map.Entry<String, Object> param : params.entrySet()) {
            if (param.getKey() != null && !"".equals(param.getKey()) && param.getValue() != null && !""
                .equals(param.getValue())) {
                stringer.key(param.getKey()).value(param.getValue());
            }
        }

        return stringer.endObject().toString();
    }
View Full Code Here

        return "";
    }

    @Override
    public String toJSONString() {
        JSONStringer stringer = new JSONStringer();
        try
        {
            stringer.object();
            toJSONString(stringer);
            stringer.endObject();
        }
        catch (JSONException e)
        {
            throw new RuntimeException("Failed to serialize " + this, e);
//            System.exit(-1);
        }
        return stringer.toString();
    }
View Full Code Here

        m_parameters.addAll(parameters);
    }

    @Override
    public String toJSONString() {
        JSONStringer stringer = new JSONStringer();
        try {
            stringer.object();
            toJSONString(stringer);
            stringer.endObject();
        } catch (JSONException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
        return stringer.toString();
    }
View Full Code Here

        return 0;
    }

    @Override
    public String toJSONString() {
        JSONStringer stringer = new JSONStringer();
        try {
            stringer.object();
            super.toJSONString(stringer);

            stringer.key(Members.EXECUTE_LIST.name()).array();
            for (AbstractPlanNode node : m_list) {
                stringer.value(node.getPlanNodeId().intValue());
            }
            stringer.endArray(); //end execution list

            stringer.endObject(); //end PlanNodeList
        } catch (JSONException e) {
            // HACK ugly ugly to make the JSON handling
            // in QueryPlanner generate a JSONException for a plan we know
            // here that we can't serialize.  Making this method throw
            // JSONException pushes that exception deep into the bowels of
            // Volt with no good place to catch it and handle the error.
            // Consider this the coward's way out.
            throw new RuntimeException("Failed to serialize PlanNodeList", e);
//            return "This JSON error message is a lie";
        }
        return stringer.toString();
    }
View Full Code Here

    private String separator;
    private String[] tokenSeparators;

    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, "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, "createSearchChoice", createSearchChoice);
      Json.writeFunction(writer, "initSelection", initSelection);
      Json.writeFunction(writer, "query", query);
      Json.writeObject(writer, "width", width);
      Json.writeObject(writer, "openOnEnter", openOnEnter);
      Json.writeObject(writer, "containerCss", containerCss);
      Json.writeObject(writer, "containerCssClass", containerCssClass);
      Json.writeObject(writer, "dropdownCss", dropdownCss);
      Json.writeObject(writer, "dropdownCssClass", dropdownCssClass);
      Json.writeObject(writer, "separator", separator);
      Json.writeObject(writer, "tokenSeparators", tokenSeparators);
      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

TOP

Related Classes of org.json.JSONStringer

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.