net.sf.json.JSON.write()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(5.4k)|赞(0)|评价(0)|浏览(193)

本文整理了Java中net.sf.json.JSON.write()方法的一些代码示例,展示了JSON.write()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSON.write()方法的具体详情如下:
包路径:net.sf.json.JSON
类名称:JSON
方法名:write

JSON.write介绍

暂无

代码示例

代码示例来源:origin: org.geoserver/rest

@Override
protected void write(Object object, OutputStream out) throws IOException {
  //TODO: character set
  Writer outWriter = new BufferedWriter(new OutputStreamWriter(out));
  //JD: why does this initial flush occur?
  outWriter.flush();
  JSON obj = (JSON)toJSONObject(object);
  obj.write(outWriter);
  outWriter.flush();
}

代码示例来源:origin: org.geoserver/gs-restconfig

@Override
public void writeInternal(Map<?, ?> map, HttpOutputMessage outputMessage)
    throws IOException, HttpMessageNotWritableException {
  // TODO: character set
  Writer outWriter = new BufferedWriter(new OutputStreamWriter(outputMessage.getBody()));
  // JD: why does this initial flush occur?
  outWriter.flush();
  JSON obj = (JSON) toJSONObject(map);
  obj.write(outWriter);
  outWriter.flush();
}

代码示例来源:origin: pl.edu.icm.yadda/yaddaweb-lite-core

protected void writeJSON(Map model, HttpServletRequest request,
    HttpServletResponse response) throws Exception {
  JSON json = createJSON(model, request, response);
  json = (JSON) (((JSONObject) json).get(modelItemKey));
  json.write(response.getWriter());
}

代码示例来源:origin: org.kohsuke.stapler/stapler

protected boolean handleJSON(StaplerResponse rsp, Object response) throws IOException {
    if (response instanceof JSON) {
      rsp.setContentType(Flavor.JSON.contentType);
      ((JSON)response).write(rsp.getWriter());
      return true;
    }
    return false;
  }
}

代码示例来源:origin: org.hudsonci.stapler/stapler-core

protected boolean handleJSON(StaplerResponse rsp, Object response) throws IOException {
    if (response instanceof JSON) {
      rsp.setContentType(Flavor.JSON.contentType);
      ((JSON)response).write(rsp.getWriter());
      return true;
    }
    return false;
  }
}

代码示例来源:origin: stapler/stapler

protected boolean handleJSON(StaplerResponse rsp, Object response) throws IOException {
    if (response instanceof JSON) {
      rsp.setContentType(Flavor.JSON.contentType);
      ((JSON)response).write(rsp.getWriter());
      return true;
    }
    return false;
  }
}

代码示例来源:origin: miltonio/milton2

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();
  }
}

代码示例来源:origin: miltonio/milton2

map.put("error", errorMessage);
JSON json = JSONSerializer.toJSON(map, cfg);
json.write(writer);
json.write(writer);

代码示例来源:origin: miltonio/milton2

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();
}

代码示例来源:origin: miltonio/milton2

json = JSONSerializer.toJSON(list, cfg);
json.write(writer);
writer.flush();

代码示例来源:origin: org.jenkins-ci.plugins/pipeline-utility-steps

@Override
protected Void run() throws Exception {
  if (step.getJson() == null) {
    throw new IllegalArgumentException(Messages.WriteJSONStepExecution_missingJSON(step.getDescriptor().getFunctionName()));
  }
  if (StringUtils.isBlank(step.getFile())) {
    throw new IllegalArgumentException(Messages.WriteJSONStepExecution_missingFile(step.getDescriptor().getFunctionName()));
  }
  if (isNotBlank(step.getFile()) && ws == null) {
    // Need a workspace if we are writing to a file.
    throw new MissingContextVariableException(FilePath.class);
  }
  FilePath path = ws.child(step.getFile());
  if (path.isDirectory()) {
    throw new FileNotFoundException(Messages.JSONStepExecution_fileIsDirectory(path.getRemote()));
  }
  try (OutputStreamWriter writer = new OutputStreamWriter(path.write())) {
    if (step.getPretty() > 0) {
      writer.write(step.getJson().toString(step.getPretty()));
    } else {
      step.getJson().write(writer);
    }
  }
  return null;
}

代码示例来源:origin: net.sf.spring-json/spring-json

logger.debug(json.toString());
json.write(writer);
writer.flush();

代码示例来源:origin: jenkinsci/pipeline-utility-steps-plugin

@Override
protected Void run() throws Exception {
  FilePath ws = getContext().get(FilePath.class);
  assert ws != null;
  if (step.getJson() == null) {
    throw new IllegalArgumentException(Messages.WriteJSONStepExecution_missingJSON(step.getDescriptor().getFunctionName()));
  }
  if (StringUtils.isBlank(step.getFile())) {
    throw new IllegalArgumentException(Messages.WriteJSONStepExecution_missingFile(step.getDescriptor().getFunctionName()));
  }
  FilePath path = ws.child(step.getFile());
  if (path.isDirectory()) {
    throw new FileNotFoundException(Messages.JSONStepExecution_fileIsDirectory(path.getRemote()));
  }
  try (OutputStreamWriter writer = new OutputStreamWriter(path.write(), "UTF-8")) {
    if (step.getPretty() > 0) {
      writer.write(step.getJson().toString(step.getPretty()));
    } else {
      step.getJson().write(writer);
    }
  }
  return null;
}

相关文章