Package org.codehaus.jettison.json

Examples of org.codehaus.jettison.json.JSONWriter


   * Gets JSON string from a collection of goods or categories
   */
  private String getItemsJson(Iterable<? extends Jsonable<?>> items)
      throws JSONException {
    JSONStringer st = new JSONStringer();
    JSONWriter writer = st.array();
    for(Jsonable<?> i: items) {
      writer = writer.value(new JSONObject(i.toJson()));
    }
    writer = writer.endArray();
   
    return writer.toString();
  }
View Full Code Here


    }
  }

  public String toJson() {
    try {
      JSONWriter writer = new JSONStringer().object();
      if(key != null) {
        writer = writer.key(Jsonable.KEY_STR).value(KeyFactory.keyToString(key));
      }
      JSONWriter value = writer
      .key(Category.NAME).value(getName())
      .key(Category.DESCRIPTION).value(getDescription().getValue())
      .key(Category.PARENT_KEY_STR).value(getParentKeyStr())
      .key(Category.IMAGE_BLOB_KEY).value(getImageBlobKey());
     
      value = addAdditionalPropertiesToJson(value);
      String string = value.endObject().toString();
     
      return string;
    } catch (JSONException e) {
      throw new RuntimeException(e);
    }
View Full Code Here

    }

    @Override
    public void encode(Object value, OutputStream os) throws Exception {
        OutputStreamWriter writer = new OutputStreamWriter(os);
        JSONWriter w = new JSONWriter(writer);
       
        encode((Map) value, w);
        writer.flush();
    }
View Full Code Here

TOP

Related Classes of org.codehaus.jettison.json.JSONWriter

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.