Examples of JsonWriter


Examples of org.json.JSONWriter

   public void writeTo(Resource resource, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException
   {
      PrintWriter printWriter = new PrintWriter(entityStream);
      try
      {
         JSONWriter writer  =  new JSONWriter(printWriter);
         writer.object().key("description").value(resource.getDescription());
         writer.key("children").array();
         for (Child child : resource.getChildren())
         {
            writeChild(child, writer);
         }
         writer.endArray();
         if (resource.getOperations() != null)
         {
            writer.key("operations").array();
            for (Operation operation : resource.getOperations())
            {
               writeOperation(operation, writer);
            }
            writer.endArray();
         }
         writer.endObject();

         printWriter.flush();
      }
      catch (JSONException e)
      {
View Full Code Here

Examples of org.json.JSONWriter

    private void writeJSON(final PrintWriter pw) throws IOException {
        final Set<Group> groups = groupManager.listAllGroups();
        final Set<Node> nodes = clusterManager.listNodes();

        final JSONWriter jw = new JSONWriter(pw);

        try {
            jw.object();
            jw.key("status");
            jw.value(getStatusLine(groups, nodes));
            jw.key("groups");
            jw.array();
            for (Group g : groups) {
                jw.object();
                jw.key("name");
                jw.value(g.getName());

                Set<Node> members = g.getNodes();
                jw.key("members");
                jw.array();
                if (nodes != null) {
                    for (Node n : members) {
                        jw.object();
                        jw.key("id");
                        jw.value(n.getId());
                        jw.endObject();
                    }
                }

                jw.endArray();
                jw.key("actions");
                jw.array();
                boolean enable = true;
                action(jw, enable, "deleteGroup", "Delete Group", "delete");
                jw.endArray();
                jw.endObject();
            }
            jw.endArray();
            jw.endObject();
        } catch (JSONException je) {
            throw new IOException(je.toString());
        }
    }
View Full Code Here

Examples of org.jvnet.sorcerer.util.JsonWriter

        w.close();
    }

    public void generateProjectJs(final Map<String, String> cus, PrintWriter w) throws IOException {
        try {
            final JsonWriter jw = new JsonWriter(w);
            jw.startObject();
            jw.property("name", "Project"); // TODO
            jw.propertyUnquoted("linker", "linker.self");
            jw.property("sources", new JsonWriter.Writable() {
                public void write(JsonWriter w) {
                    for (Map.Entry<String, String> entry : cus.entrySet()) {
                        jw.property(entry.getKey(), entry.getValue());
                    }
                }
            });
            // write dependencies
            for (Dependency dep : pss.getDependencies()) {
                jw.object(dep);
            }
            jw.endObject();
        } finally {
            w.close();
        }
    }
View Full Code Here

Examples of org.ofbiz.base.json.JSONWriter

            writer.write(str);
            return true;
        } else {
            StringWriter sw = new StringWriter();
            IndentingWriter indenting = new IndentingWriter(writer, true, false);
            JSONWriter jsonWriter;
            if (allowJsonResolve) {
                jsonWriter = new JSONWriter(indenting, JSONWriter.ResolvingFallbackHandler);
            } else {
                jsonWriter = new JSONWriter(indenting);
            }
            jsonWriter.write(value);
            writer.write(sw.toString());
            return true;
        }
    }
View Full Code Here

Examples of org.ofbiz.base.json.JSONWriter

        return new JSON(new StringReader(value)).allowResolve(allowResolve).JSONValue();
    }

    protected String getJSON(Object object, boolean allowResolve) throws Exception {
        StringWriter writer = new StringWriter();
        JSONWriter jsonWriter;
        if (allowResolve) {
            jsonWriter = new JSONWriter(writer, JSONWriter.ResolvingFallbackHandler);
        } else {
            jsonWriter = new JSONWriter(writer);
        }
        assertTrue("writer is IndentingWriter", jsonWriter.getWriter() instanceof IndentingWriter);
        jsonWriter.write(object);
        return writer.toString();
    }
View Full Code Here

Examples of org.ofbiz.base.json.JSONWriter

        assertEquals("write " + type, json, getJSON(obj, true));
        assertEquals("parse " + type, obj, parseJSON(json, true));
    }

    public void testClose() throws Exception {
        JSONWriter writer = new JSONWriter(new OutputStreamWriter(new ByteArrayOutputStream()));
        writer.close();
        IOException caught = null;
        try {
            writer.write("");
        } catch (IOException e) {
            caught = e;
        } finally {
            assertNotNull("write after close", caught);
        }
View Full Code Here

Examples of org.openjena.atlas.json.io.JsonWriter

    }
   
    @Override
    public void output(IndentedWriter out)
    {
        JsonWriter w = new JsonWriter(out) ;
        w.startOutput() ;
        this.visit(w) ;
        w.finishOutput() ;
    }
View Full Code Here

Examples of org.owasp.passfault.io.JsonWriter

  public void testPatternToJSON() throws IOException {
    MockPasswordResults results = new MockPasswordResults("test");
    results.foundPattern(new PasswordPattern(1, 2, "te", 300, "This is a test pattern", "testPattern", "test"));
    results.foundPattern(new PasswordPattern(3, 2, "st", 350, "This is another test pattern", "testPattern2", "test"));
    PathCost pathCost = results.calculateHighestProbablePatterns();
    JsonWriter writer = new JsonWriter();
    writer.write(new PrintWriter(System.out, true), pathCost);
  }
View Full Code Here

Examples of org.richfaces.json.JSONWriter

  /**
   * Create default column visibility based on component children.
   */
  private void createDefaultColumnsVisibility(UIExtendedDataTable extendedDataTable){
    try {
      JSONWriter writer = new JSONStringer().object();
      for (Iterator<UIColumn> iter = extendedDataTable.getChildColumns(); iter.hasNext();) {
        UIColumn col = iter.next();
        writer.key(col.getId()).value(col.isVisible() ? TRUE : FALSE);
      }
      value = new JSONObject(writer.endObject().toString());
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }//createDefaultColumnsVisibility
View Full Code Here

Examples of org.slim3.datastore.json.JsonWriter

     *
     * @return JSON string
     */
    public String modelToJson(final Object model, int maxDepth){
        StringBuilder b = new StringBuilder();
        JsonWriter w = new JsonWriter(b, new ModelWriter() {
            @Override
            public void write(JsonWriter writer, Object model, int maxDepth,
                    int currentDepth) {
                invokeModelToJson(
                    Datastore.getModelMeta(model.getClass()),
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.