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


Java JsonFormat.Printer方法代码示例

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


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

示例1: getDefaultRequestJSON

import com.google.protobuf.util.JsonFormat; //导入方法依赖的package包/类
private JsonNode getDefaultRequestJSON(Message msg) throws JsonParseException, IOException
{
	Message.Builder o2 = DefaultCustomPredictRequest.newBuilder();
	TypeRegistry registry = TypeRegistry.newBuilder().add(o2.getDescriptorForType()).build();
	JsonFormat.Printer jPrinter = JsonFormat.printer();
	String result = jPrinter.usingTypeRegistry(registry).print(msg);
	ObjectMapper mapper = new ObjectMapper();
	JsonFactory factory = mapper.getFactory();
	JsonParser parser = factory.createParser(result);
	JsonNode jNode = mapper.readTree(parser);
	if (jNode.has(PredictionBusinessServiceImpl.REQUEST_CUSTOM_DATA_FIELD))
	{
		JsonNode values = jNode.get(PredictionBusinessServiceImpl.REQUEST_CUSTOM_DATA_FIELD).get("values");
		((ObjectNode) jNode).set(PredictionBusinessServiceImpl.REQUEST_CUSTOM_DATA_FIELD, values);
	}
	return jNode;
}
 
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:18,代码来源:ClientRpcStore.java

示例2: get

import com.google.protobuf.util.JsonFormat; //导入方法依赖的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

示例3: getJsonPrinter

import com.google.protobuf.util.JsonFormat; //导入方法依赖的package包/类
private JsonFormat.Printer getJsonPrinter() {
  if (mJsonPrinter == null) {
    TypeRegistry typeRegistry = TypeRegistry.newBuilder()
        .add(Entity.getDescriptor())
        .build();

    mJsonPrinter = JsonFormat.printer()
        .usingTypeRegistry(typeRegistry)
        .omittingInsignificantWhitespace();
  }
  return mJsonPrinter;
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:13,代码来源:DatastoreToGcs.java

示例4: createPrinter

import com.google.protobuf.util.JsonFormat; //导入方法依赖的package包/类
public static JsonFormat.Printer createPrinter() {
  TypeRegistry typeRegistry = TypeRegistry.newBuilder()
    .add(Entity.getDescriptor())
    .build();

  return JsonFormat.printer()
      .usingTypeRegistry(typeRegistry)
      .omittingInsignificantWhitespace();
}
 
开发者ID:cobookman,项目名称:DatastoreToGCS,代码行数:10,代码来源:GCSBackup.java

示例5: getJSONFromMethod

import com.google.protobuf.util.JsonFormat; //导入方法依赖的package包/类
private JsonNode getJSONFromMethod(Method m,Message msg,String fieldname) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, JsonParseException, IOException
{
	Message.Builder o2 = (Message.Builder) m.invoke(null);
	TypeRegistry registry = TypeRegistry.newBuilder().add(o2.getDescriptorForType()).build();
	
	JsonFormat.Printer jPrinter = JsonFormat.printer();
	String result = jPrinter.usingTypeRegistry(registry).print(msg);
	ObjectMapper mapper = new ObjectMapper();
	JsonFactory factory = mapper.getFactory();
	JsonParser parser = factory.createParser(result);
	JsonNode jNode = mapper.readTree(parser);
	if (jNode.has(fieldname) && jNode.get(fieldname).has("@type"))
		((ObjectNode) jNode.get(fieldname)).remove("@type");
	return jNode;
}
 
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:16,代码来源:ClientRpcStore.java

示例6: getJSON

import com.google.protobuf.util.JsonFormat; //导入方法依赖的package包/类
private JsonNode getJSON(Message msg,String fieldname) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, JsonParseException, IOException
{
	JsonFormat.Printer jPrinter = JsonFormat.printer();
	String result = jPrinter.print(msg);
	ObjectMapper mapper = new ObjectMapper();
	JsonFactory factory = mapper.getFactory();
	JsonParser parser = factory.createParser(result);
	JsonNode jNode = mapper.readTree(parser);
	return jNode;
}
 
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:11,代码来源:ClientRpcStore.java

示例7: dump

import com.google.protobuf.util.JsonFormat; //导入方法依赖的package包/类
public static void dump(File src) throws Exception {
	try(FileInputStream f = new FileInputStream(src)) {
		Data data = Data.parseFrom(f);
		JsonFormat.Printer printer = JsonFormat.printer().usingTypeRegistry(TypeRegistry.getEmptyTypeRegistry());
		System.out.println(printer.print(data));
	}
}
 
开发者ID:xbuf,项目名称:jme3_xbuf,代码行数:8,代码来源:JsonTools.java

示例8: MessageWriter

import com.google.protobuf.util.JsonFormat; //导入方法依赖的package包/类
@VisibleForTesting
MessageWriter(JsonFormat.Printer jsonPrinter, Output output) {
  this.jsonPrinter = jsonPrinter;
  this.output = output;
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:6,代码来源:MessageWriter.java

示例9: generateOutputFiles

import com.google.protobuf.util.JsonFormat; //导入方法依赖的package包/类
private void generateOutputFiles(Service serviceConfig)
    throws FileNotFoundException, IOException {
  // Create normalized service proto, in binary form.
  if (!Strings.isNullOrEmpty(options.get(BIN_OUT))) {
    File outFileBinaryServiceConfig = new File(options.get(BIN_OUT));
    OutputStream normalizedOut = new FileOutputStream(outFileBinaryServiceConfig);
    serviceConfig.writeTo(normalizedOut);
    normalizedOut.close();
  }

  // Create normalized service proto, in text form.
  if (!Strings.isNullOrEmpty(options.get(TXT_OUT))) {
    File outFileTxtServiceConfig = new File(options.get(TXT_OUT));
    try (PrintWriter textPrintWriter =
        new PrintWriter(outFileTxtServiceConfig, StandardCharsets.UTF_8.name())) {
      TextFormat.print(serviceConfig, textPrintWriter);
    }
  }

  // Create normalized service proto, in json form.
  if (!Strings.isNullOrEmpty(options.get(JSON_OUT))) {
    File outFileJsonServiceConfig = new File(options.get(JSON_OUT));
    TypeRegistry registry =
        addPlatformExtensions(TypeRegistry.newBuilder())
            .add(Service.getDescriptor())
            .add(com.google.protobuf.BoolValue.getDescriptor())
            .add(com.google.protobuf.BytesValue.getDescriptor())
            .add(com.google.protobuf.DoubleValue.getDescriptor())
            .add(com.google.protobuf.FloatValue.getDescriptor())
            .add(com.google.protobuf.Int32Value.getDescriptor())
            .add(com.google.protobuf.Int64Value.getDescriptor())
            .add(com.google.protobuf.StringValue.getDescriptor())
            .add(com.google.protobuf.UInt32Value.getDescriptor())
            .add(com.google.protobuf.UInt64Value.getDescriptor())
            .build();
    JsonFormat.Printer jsonPrinter = JsonFormat.printer().usingTypeRegistry(registry);
    try (PrintWriter jsonPrintWriter =
        new PrintWriter(outFileJsonServiceConfig, StandardCharsets.UTF_8.name())) {
      jsonPrinter.appendTo(serviceConfig, jsonPrintWriter);
    }
  }
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:43,代码来源:ConfigGeneratorDriver.java

示例10: toJSON

import com.google.protobuf.util.JsonFormat; //导入方法依赖的package包/类
/**
 * Format a Protocol Buffers Message to a JSON string
 * @param data  The Message to be formatted
 * @return  A JSON String representing the data
 * @throws InvalidProtocolBufferException   Thrown in case of invalid Message data
 */
public static String toJSON(Message data) throws InvalidProtocolBufferException {
    JsonFormat.Printer printer = JsonFormat.printer();
    return printer.print(data);
}
 
开发者ID:whiver,项目名称:nifi-protobuf-processor,代码行数:11,代码来源:JSONMapper.java


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