Search in sources :

Example 26 with JsonConfig

use of net.sf.json.JsonConfig in project lobcder by skoulouzis.

the class PropPatchJsonResource method sendContent.

public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException, NotAuthorizedException {
    log.debug("sendContent");
    JsonConfig cfg = new JsonConfig();
    cfg.setIgnoreTransientFields(true);
    cfg.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
    List<FieldError> errors = new ArrayList<FieldError>();
    if (resp != null && resp.getErrorProperties() != null) {
        log.debug("error props: " + resp.getErrorProperties().size());
        for (Status stat : resp.getErrorProperties().keySet()) {
            List<NameAndError> props = resp.getErrorProperties().get(stat);
            for (NameAndError ne : props) {
                errors.add(new FieldError(ne.getName().getLocalPart(), ne.getError(), stat.code));
            }
        }
    }
    log.debug("errors size: " + errors.size());
    FieldError[] arr = new FieldError[errors.size()];
    arr = errors.toArray(arr);
    Writer writer = new PrintWriter(out);
    JSON json = JSONSerializer.toJSON(arr, cfg);
    json.write(writer);
    writer.flush();
}
Also used : Status(io.milton.http.Response.Status) NameAndError(io.milton.http.webdav.PropFindResponse.NameAndError) JsonConfig(net.sf.json.JsonConfig) ArrayList(java.util.ArrayList) JSON(net.sf.json.JSON) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) PrintWriter(java.io.PrintWriter)

Example 27 with JsonConfig

use of net.sf.json.JsonConfig in project lobcder by skoulouzis.

the class PutJsonResource method sendContent.

/**
 * Returns a JSON representation of the newly created hrefs
 *
 * @param out
 * @param range
 * @param params
 * @param contentType
 * @throws IOException
 * @throws NotAuthorizedException
 */
@Override
public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException, NotAuthorizedException {
    JsonConfig cfg = new JsonConfig();
    cfg.setIgnoreTransientFields(true);
    cfg.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
    NewFile[] arr;
    if (newFiles != null) {
        arr = new NewFile[newFiles.size()];
        newFiles.toArray(arr);
    } else {
        arr = new NewFile[0];
    }
    Writer writer = new PrintWriter(out);
    JSON json = JSONSerializer.toJSON(arr, cfg);
    json.write(writer);
    writer.flush();
}
Also used : JsonConfig(net.sf.json.JsonConfig) JSON(net.sf.json.JSON) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) PrintWriter(java.io.PrintWriter)

Example 28 with JsonConfig

use of net.sf.json.JsonConfig in project lobcder by skoulouzis.

the class JsonWriter method write.

public void write(Object object, OutputStream out) throws IOException {
    JsonConfig cfg = new JsonConfig();
    cfg.setIgnoreTransientFields(true);
    cfg.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
    JSON json = JSONSerializer.toJSON(object, cfg);
    Writer writer = new PrintWriter(out);
    json.write(writer);
    writer.flush();
}
Also used : JsonConfig(net.sf.json.JsonConfig) JSON(net.sf.json.JSON) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) PrintWriter(java.io.PrintWriter)

Aggregations

JsonConfig (net.sf.json.JsonConfig)28 JSONObject (net.sf.json.JSONObject)17 File (java.io.File)10 HashMap (java.util.HashMap)10 JSONArray (net.sf.json.JSONArray)10 Test (org.junit.Test)10 URL (java.net.URL)7 PrintWriter (java.io.PrintWriter)5 JSON (net.sf.json.JSON)5 Writer (java.io.Writer)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 NewBeanInstanceStrategy (net.sf.json.util.NewBeanInstanceStrategy)2 FlexClass (org.jaffa.flexfields.FlexClass)2 FlexCriteriaBean (org.jaffa.flexfields.FlexCriteriaBean)2 Status (io.milton.http.Response.Status)1 NameAndError (io.milton.http.webdav.PropFindResponse.NameAndError)1 CollectionResource (io.milton.resource.CollectionResource)1