当前位置: 首页>>代码示例>>Java>>正文


Java JsonWriter.formatJson方法代码示例

本文整理汇总了Java中com.cedarsoftware.util.io.JsonWriter.formatJson方法的典型用法代码示例。如果您正苦于以下问题:Java JsonWriter.formatJson方法的具体用法?Java JsonWriter.formatJson怎么用?Java JsonWriter.formatJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.cedarsoftware.util.io.JsonWriter的用法示例。


在下文中一共展示了JsonWriter.formatJson方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: save

import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
@Override
public void save(Player player) throws Exception {
    // Checking if file exists
    File file = new File(getStorageDirectory() + player.getAttributes().getUsername() + ".json");

    if (!file.exists()) {
        file.createNewFile();
    } else {
        file.delete();
    }

    // Generating pretty json
    Map<String, Object> args = new HashMap<>();
    args.put("JsonWriter.PRETTY_PRINT", true);
    String json = JsonWriter.objectToJson(player.getAttributes(), args);
    json = JsonWriter.formatJson(json);

    // Writing json
    FileWriter writer = new FileWriter(file);
    writer.write(json);
    writer.close();
}
 
开发者ID:PureCS,项目名称:runesource,代码行数:23,代码来源:JsonPlayerFileHandler.java

示例2: get

import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" })
public Response get(@Context Response response, @QueryParam(LumongoConstants.PRETTY) boolean pretty) {

	try {
		Lumongo.GetIndexesResponse getIndexesResponse = indexManager.getIndexes(Lumongo.GetIndexesRequest.newBuilder().build());

		Document mongoDocument = new org.bson.Document();
		mongoDocument.put("indexes", getIndexesResponse.getIndexNameList());
		String docString = JSONSerializers.getStrict().serialize(mongoDocument);

		if (pretty) {
			docString = JsonWriter.formatJson(docString);
		}

		return Response.status(LumongoConstants.SUCCESS).entity(docString).build();

	}
	catch (Exception e) {
		return Response.status(LumongoConstants.INTERNAL_ERROR).entity("Failed to get index names: " + e.getMessage()).build();
	}

}
 
开发者ID:lumongo,项目名称:lumongo,代码行数:24,代码来源:IndexesResource.java

示例3: get

import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" })
public Response get(@Context Response response, @QueryParam(LumongoConstants.INDEX) String index, @QueryParam(LumongoConstants.PRETTY) boolean pretty) {

	try {
		StringBuilder responseBuilder = new StringBuilder();

		IndexConfig indexConfig = indexManager.getIndexConfig(index);

		responseBuilder.append("{");
		responseBuilder.append("\"indexName\": ");
		responseBuilder.append("\"");
		responseBuilder.append(indexConfig.getIndexName());
		responseBuilder.append("\"");
		responseBuilder.append(",");
		responseBuilder.append("\"numberOfSegments\": ");
		responseBuilder.append(indexConfig.getNumberOfSegments());
		responseBuilder.append(",");
		responseBuilder.append("\"indexSettings\": ");
		JsonFormat.Printer printer = JsonFormat.printer();
		responseBuilder.append(printer.print(indexConfig.getIndexSettings()));
		responseBuilder.append("}");

		String docString = responseBuilder.toString();

		if (pretty) {
			docString = JsonWriter.formatJson(docString);
		}

		return Response.status(LumongoConstants.SUCCESS).entity(docString).build();

	}
	catch (Exception e) {
		return Response.status(LumongoConstants.INTERNAL_ERROR).entity("Failed to get index names: " + e.getMessage()).build();
	}

}
 
开发者ID:lumongo,项目名称:lumongo,代码行数:38,代码来源:IndexResource.java

示例4: get

import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" })
public Response get(@Context Response response, @QueryParam(LumongoConstants.INDEX) final String indexName,
		@QueryParam(LumongoConstants.PRETTY) boolean pretty) {

	if (indexName != null) {

		Lumongo.GetFieldNamesRequest fieldNamesRequest = Lumongo.GetFieldNamesRequest.newBuilder().setIndexName(indexName).build();

		Lumongo.GetFieldNamesResponse fieldNamesResponse;

		try {
			fieldNamesResponse = indexManager.getFieldNames(fieldNamesRequest);

			Document mongoDocument = new Document();
			mongoDocument.put("index", indexName);
			mongoDocument.put("fields", fieldNamesResponse.getFieldNameList());

			String docString = JSONSerializers.getStrict().serialize(mongoDocument);

			if (pretty) {
				docString = JsonWriter.formatJson(docString);
			}

			return Response.status(LumongoConstants.SUCCESS).entity(docString).build();

		}
		catch (Exception e) {
			return Response.status(LumongoConstants.INTERNAL_ERROR).entity("Failed to fetch fields for index <" + indexName + ">: " + e.getMessage())
					.build();
		}
	}
	else {
		return Response.status(LumongoConstants.INTERNAL_ERROR).entity("No index defined").build();
	}

}
 
开发者ID:lumongo,项目名称:lumongo,代码行数:38,代码来源:FieldsResource.java

示例5: get

import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" })
public Response get(@Context Response response, @QueryParam(LumongoConstants.PRETTY) boolean pretty) {

	try {

		Document mongoDocument = new Document();

		mongoDocument.put("indexBlockSize", indexManager.getClusterConfig().getIndexBlockSize());
		mongoDocument.put("maxIndexBlockCount", indexManager.getClusterConfig().getMaxIndexBlocks());
		mongoDocument.put("currentIndexBlockCount", MongoFile.getCacheSize());

		Runtime runtime = Runtime.getRuntime();

		mongoDocument.put("jvmUsedMemoryMB", (runtime.totalMemory() - runtime.freeMemory()) / MB);
		mongoDocument.put("jvmFreeMemoryMB", runtime.freeMemory() / MB);
		mongoDocument.put("jvmTotalMemoryMB", runtime.totalMemory() / MB);
		mongoDocument.put("jvmMaxMemoryMB", runtime.maxMemory() / MB);

		String docString = JSONSerializers.getStrict().serialize(mongoDocument);

		if (pretty) {
			docString = JsonWriter.formatJson(docString);
		}

		return Response.status(LumongoConstants.SUCCESS).entity(docString).build();

	}
	catch (Exception e) {
		return Response.status(LumongoConstants.INTERNAL_ERROR).entity("Failed to get cluster membership: " + e.getMessage()).build();
	}

}
 
开发者ID:lumongo,项目名称:lumongo,代码行数:34,代码来源:StatsResource.java

示例6: toJson

import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
public String toJson() {
	return JsonWriter.formatJson(JsonWriter.objectToJson(this));
}
 
开发者ID:OHDSI,项目名称:WhiteRabbit,代码行数:4,代码来源:ETL.java

示例7: get

import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" })
public Response get(@Context Response response, @QueryParam(LumongoConstants.PRETTY) boolean pretty) {

	try {
		Lumongo.GetMembersResponse getMembersResponse = indexManager.getMembers(Lumongo.GetMembersRequest.newBuilder().build());

		org.bson.Document mongoDocument = new org.bson.Document();

		List<Document> memberObjList = new ArrayList<>();
		for (Lumongo.LMMember lmMember : getMembersResponse.getMemberList()) {
			Document memberObj = new Document();
			memberObj.put("serverAddress", lmMember.getServerAddress());
			memberObj.put("hazelcastPort", lmMember.getHazelcastPort());
			memberObj.put("internalPort", lmMember.getInternalPort());
			memberObj.put("externalPort", lmMember.getExternalPort());

			Document indexMappingObj = new Document();
			for (Lumongo.IndexMapping indexMapping : getMembersResponse.getIndexMappingList()) {

				TreeSet<Integer> segments = new TreeSet<>();
				for (Lumongo.SegmentMapping segmentMapping : indexMapping.getSegmentMappingList()) {
					if (segmentMapping.getMember().equals(lmMember)) {
						segments.add(segmentMapping.getSegmentNumber());
					}
				}

				indexMappingObj.put(indexMapping.getIndexName(), segments);
			}
			memberObj.put("indexMapping", indexMappingObj);


			memberObjList.add(memberObj);

		}

		mongoDocument.put("members", memberObjList);

		String docString = JSONSerializers.getStrict().serialize(mongoDocument);

		if (pretty) {
			docString = JsonWriter.formatJson(docString);
		}

		return Response.status(LumongoConstants.SUCCESS).entity(docString).build();

	}
	catch (Exception e) {
		return Response.status(LumongoConstants.INTERNAL_ERROR).entity("Failed to get cluster membership: " + e.getMessage()).build();
	}

}
 
开发者ID:lumongo,项目名称:lumongo,代码行数:53,代码来源:MembersResource.java

示例8: get

import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" })
public Response get(@Context Response response, @QueryParam(LumongoConstants.ID) final String uniqueId,
		@QueryParam(LumongoConstants.INDEX) final String indexName, @QueryParam(LumongoConstants.PRETTY) boolean pretty) {

	Lumongo.FetchRequest.Builder fetchRequest = Lumongo.FetchRequest.newBuilder();
	fetchRequest.setIndexName(indexName);
	fetchRequest.setUniqueId(uniqueId);

	Lumongo.FetchResponse fetchResponse;

	try {
		fetchResponse = indexManager.fetch(fetchRequest.build());

		if (fetchResponse.hasResultDocument()) {
			Document document = ResultHelper.getDocumentFromResultDocument(fetchResponse.getResultDocument());
			String docString;
			if (pretty) {
				docString = JSONSerializers.getLegacy().serialize(document);
			}
			else {
				docString = JSONSerializers.getStrict().serialize(document);
			}

			if (pretty) {
				docString = JsonWriter.formatJson(docString);
			}

			return Response.status(LumongoConstants.SUCCESS).entity(docString).build();
		}
		else {
			return Response.status(LumongoConstants.NOT_FOUND).entity("Failed to fetch uniqueId <" + uniqueId + "> for index <" + indexName + ">").build();
		}

	}
	catch (Exception e) {
		return Response.status(LumongoConstants.INTERNAL_ERROR)
				.entity("Failed to fetch uniqueId <" + uniqueId + "> for index <" + indexName + ">: " + e.getMessage()).build();
	}

}
 
开发者ID:lumongo,项目名称:lumongo,代码行数:42,代码来源:FetchResource.java

示例9: prettyJson

import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
/**
 * Pretty-Print JSON.
 * 
 * @param json The JSON
 * @return A beautiful JSON
 */
public static String prettyJson(final Object json) {
  return JsonWriter.formatJson(json.toString());
}
 
开发者ID:mobileboxlab,项目名称:appium-java-repl,代码行数:10,代码来源:Utils.java


注:本文中的com.cedarsoftware.util.io.JsonWriter.formatJson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。