本文整理了Java中org.codehaus.jettison.json.JSONObject.toString()
方法的一些代码示例,展示了JSONObject.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.toString()
方法的具体详情如下:
包路径:org.codehaus.jettison.json.JSONObject
类名称:JSONObject
方法名:toString
[英]Make a JSON text of this JSONObject. For compactness, no whitespace is added. If this would not result in a syntactically correct JSON text, then null will be returned instead.
Warning: This method assumes that the data structure is acyclical.
[中]生成此JSONObject的JSON文本。对于紧凑性,不添加空格。如果这不会导致语法正确的JSON文本,那么将返回null。
警告:此方法假定数据结构是非循环的。
代码示例来源:origin: json-path/JsonPath
@Override
public String toJson(Object obj)
{
try
{
if( obj instanceof org.codehaus.jettison.json.JSONArray )
{
return ((org.codehaus.jettison.json.JSONArray)obj).toString(2);
}
if( obj instanceof org.codehaus.jettison.json.JSONObject )
{
return ((org.codehaus.jettison.json.JSONObject)obj).toString(2);
}
return String.valueOf(obj);
//return "\"" + String.valueOf(obj).replaceAll("\"", "\\\"") + "\"";
}
catch( org.codehaus.jettison.json.JSONException jsonException )
{
throw new IllegalStateException(jsonException);
}
}
代码示例来源:origin: Netflix/Priam
@GET
@Path("/decompress")
public Response decompress(@QueryParam("in") String in, @QueryParam("out") String out)
throws Exception {
SnappyCompression compress = new SnappyCompression();
compress.decompressAndClose(new FileInputStream(in), new FileOutputStream(out));
JSONObject object = new JSONObject();
object.put("Input compressed file", in);
object.put("Output decompress file", out);
return Response.ok(object.toString(), MediaType.APPLICATION_JSON).build();
}
}
代码示例来源:origin: Netflix/Priam
@GET
@Path("/status")
@Produces(MediaType.APPLICATION_JSON)
public Response status() throws Exception {
JSONObject object = new JSONObject();
object.put("SnapshotStatus", snapshotBackup.state().toString());
return Response.ok(object.toString(), MediaType.APPLICATION_JSON).build();
}
代码示例来源:origin: Netflix/Priam
@GET
@Path("/status/{date}/snapshots")
@Produces(MediaType.APPLICATION_JSON)
public Response snapshotsByDate(@PathParam("date") String date) throws Exception {
List<BackupMetadata> metadata = this.completedBkups.locate(date);
JSONObject object = new JSONObject();
List<String> snapshots = new ArrayList<>();
if (metadata != null && !metadata.isEmpty())
snapshots.addAll(
metadata.stream()
.filter(
backupMetadata ->
backupMetadata
.getBackupVersion()
.equals(BackupVersion.SNAPSHOT_BACKUP))
.map(
backupMetadata ->
DateUtil.formatyyyyMMddHHmm(backupMetadata.getStart()))
.collect(Collectors.toList()));
object.put("Snapshots", snapshots);
return Response.ok(object.toString(), MediaType.APPLICATION_JSON).build();
}
代码示例来源:origin: Netflix/Priam
@GET
@Path("/status/{date}")
@Produces(MediaType.APPLICATION_JSON)
public Response statusByDate(@PathParam("date") String date) throws Exception {
JSONObject object = new JSONObject();
Optional<BackupMetadata> backupMetadataOptional =
this.completedBkups
.locate(date)
.stream()
.filter(Objects::nonNull)
.filter(backupMetadata -> backupMetadata.getStatus() == Status.FINISHED)
.filter(
backupMetadata ->
backupMetadata
.getBackupVersion()
.equals(BackupVersion.SNAPSHOT_BACKUP))
.findFirst();
if (!backupMetadataOptional.isPresent()) {
object.put("Snapshotstatus", false);
} else {
object.put("Snapshotstatus", true);
object.put("Details", backupMetadataOptional.get().toString());
}
return Response.ok(object.toString(), MediaType.APPLICATION_JSON).build();
}
代码示例来源:origin: Netflix/Priam
@GET
@Path("/list")
/*
* Fetch the list of files for the requested date range.
*
* @param date range
* @param filter. The type of data files fetched. E.g. META will only fetch the daily snapshot meta data file (meta.json).
* @return the list of files in json format as part of the Http response body.
*/
public Response list(
@QueryParam(REST_HEADER_RANGE) String daterange,
@QueryParam(REST_HEADER_FILTER) @DefaultValue("") String filter)
throws Exception {
logger.info(
"Parameters: {backupPrefix: [{}], daterange: [{}], filter: [{}]}",
config.getBackupPrefix(),
daterange,
filter);
DateUtil.DateRange dateRange = new DateUtil.DateRange(daterange);
Iterator<AbstractBackupPath> it =
backupFs.list(
config.getBackupPrefix(),
Date.from(dateRange.getStartTime()),
Date.from(dateRange.getEndTime()));
JSONObject object = new JSONObject();
object = constructJsonResponse(object, it, filter);
return Response.ok(object.toString(2), MediaType.APPLICATION_JSON).build();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
fieldDTO.setValues(new JSONObject(enumMap).toString());
} else if (field.getFieldType().equals("ADDITIONAL_FOREIGN_KEY")) {
fieldDTO.setOperators("blcFilterOperators_Selectize");
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* Make a prettyprinted JSON text of this JSONObject.
* <p>
* Warning: This method assumes that the data structure is acyclical.
* @param indentFactor The number of spaces to add to each level of
* indentation.
* @return a printable, displayable, portable, transmittable
* representation of the object, beginning
* with <code>{</code> <small>(left brace)</small> and ending
* with <code>}</code> <small>(right brace)</small>.
* @throws JSONException If the object contains an invalid number.
*/
public String toString(int indentFactor) throws JSONException {
return toString(indentFactor, 0);
}
代码示例来源:origin: apache/nifi
try {
final JSONObject output = result.getJSONObject("data");
flowFile = session.write(flowFile, out -> out.write(output.toString().getBytes()));
flowFile = session.putAttribute(flowFile, CoreAttributes.MIME_TYPE.key(), LivySessionService.APPLICATION_JSON);
session.transfer(flowFile, REL_SUCCESS);
flowFile = session.write(flowFile, out -> out.write(result.toString().getBytes()));
flowFile = session.putAttribute(flowFile, CoreAttributes.MIME_TYPE.key(), LivySessionService.APPLICATION_JSON);
flowFile = session.penalize(flowFile);
代码示例来源:origin: com.sun.jersey/jersey-json
static String asJsonObject(Map map) {
return (null == map) ? "{}" : (new JSONObject(map)).toString();
}
}
代码示例来源:origin: com.jayway.jsonpath/json-path
@Override
public String toJson(Object obj)
{
try
{
if( obj instanceof org.codehaus.jettison.json.JSONArray )
{
return ((org.codehaus.jettison.json.JSONArray)obj).toString(2);
}
if( obj instanceof org.codehaus.jettison.json.JSONObject )
{
return ((org.codehaus.jettison.json.JSONObject)obj).toString(2);
}
return String.valueOf(obj);
//return "\"" + String.valueOf(obj).replaceAll("\"", "\\\"") + "\"";
}
catch( org.codehaus.jettison.json.JSONException jsonException )
{
throw new IllegalStateException(jsonException);
}
}
代码示例来源:origin: Netflix/Priam
.withStringValue(abp.getType().name()));
this.notificationService.notify(jsonObject.toString(), messageAttributes);
} catch (JSONException exception) {
logger.error(
代码示例来源:origin: org.codehaus.jettison/jettison
return ((JSONObject)value).toString(indentFactor, indent);
代码示例来源:origin: apache/phoenix
public Set<String> getSubmittedYarnApps() throws Exception {
String rmHost = PhoenixMRJobUtil.getActiveResourceManagerHost(conf, zkQuorum);
Map<String, String> urlParams = new HashMap<String, String>();
urlParams.put(YarnApplication.APP_STATES_ELEMENT, YarnApplication.state.NEW.toString()
+ "," + YarnApplication.state.ACCEPTED + "," + YarnApplication.state.SUBMITTED
+ "," + YarnApplication.state.RUNNING);
int rmPort = PhoenixMRJobUtil.getRMPort(conf);
String response = PhoenixMRJobUtil.getJobsInformationFromRM(rmHost, rmPort, urlParams);
LOG.debug("Already Submitted/Running Apps = " + response);
JSONObject jobsJson = new JSONObject(response);
JSONObject appsJson = jobsJson.optJSONObject(YarnApplication.APPS_ELEMENT);
Set<String> yarnApplicationSet = new HashSet<String>();
if (appsJson == null) {
return yarnApplicationSet;
}
JSONArray appJson = appsJson.optJSONArray(YarnApplication.APP_ELEMENT);
if (appJson == null) {
return yarnApplicationSet;
}
for (int i = 0; i < appJson.length(); i++) {
Gson gson = new GsonBuilder().create();
YarnApplication yarnApplication =
gson.fromJson(appJson.getJSONObject(i).toString(),
new TypeToken<YarnApplication>() {
}.getType());
yarnApplicationSet.add(yarnApplication.getName());
}
return yarnApplicationSet;
}
代码示例来源:origin: thinkaurelius/faunus
@Override
public void write(final NullWritable key, final FaunusVertex vertex) throws IOException {
if (null != vertex) {
this.out.write(FaunusGraphSONUtility.toJSON(vertex).toString().getBytes(UTF8));
this.out.write(NEWLINE);
}
}
代码示例来源:origin: com.tinkerpop.blueprints/blueprints-core
/**
* Creates a vertex from GraphSON using settings supplied in the constructor.
*/
public Vertex vertexFromJson(final JSONObject json) throws IOException {
return this.vertexFromJson(json.toString());
}
代码示例来源:origin: com.tinkerpop.blueprints/blueprints-core
/**
* Creates an edge from GraphSON using settings supplied in the constructor.
*/
public Edge edgeFromJson(final JSONObject json, final Vertex out, final Vertex in) throws IOException {
return this.edgeFromJson(json.toString(), out, in);
}
代码示例来源:origin: com.orientechnologies/orientdb-graphdb
/**
* Creates a vertex from GraphSON using settings supplied in the constructor.
*/
public Vertex vertexFromJson(final JSONObject json) throws IOException {
return this.vertexFromJson(json.toString());
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-core
protected final <T> Promise<T> postAndParse(final URI uri, final JSONObject entity, final JsonObjectParser<T> parser) {
final ResponsePromise responsePromise = client.newRequest(uri)
.setEntity(entity.toString())
.setContentType(JSON_CONTENT_TYPE)
.post();
return callAndParse(responsePromise, parser);
}
代码示例来源:origin: batfish/batfish
@Test
public void testLoadQuestionFromTextInvalid() {
JSONObject testQuestion = new JSONObject();
// checking if exception thrown for instance missing
_thrown.expect(BatfishException.class);
_thrown.expectMessage("Question in questionSource has no instance data");
Client.loadQuestionFromText(testQuestion.toString(), "questionSource");
}
内容来源于网络,如有侵权,请联系作者删除!