• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TypeRegistry类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



TypeRegistry类属于com.google.protobuf.util.JsonFormat包,在下文中一共展示了TypeRegistry类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getPredictRequestWithCustomDefaultFromJSON

import com.google.protobuf.util.JsonFormat.TypeRegistry; //导入依赖的package包/类
private ClassificationRequest getPredictRequestWithCustomDefaultFromJSON(JsonNode json) throws InvalidProtocolBufferException
  {
  	ObjectMapper mapper = new ObjectMapper();
  	ObjectNode data = mapper.createObjectNode();
  	data.put("@type", "type.googleapis.com/" + DefaultCustomPredictRequest.class.getName());
  	data.put("values", json.get(PredictionBusinessServiceImpl.REQUEST_CUSTOM_DATA_FIELD));
  	((ObjectNode) json).put(PredictionBusinessServiceImpl.REQUEST_CUSTOM_DATA_FIELD, data);
Message.Builder o = DefaultCustomPredictRequest.newBuilder();
TypeRegistry registry = TypeRegistry.newBuilder().add(o.getDescriptorForType()).build();
ClassificationRequest.Builder builder = ClassificationRequest.newBuilder();
JsonFormat.Parser jFormatter = JsonFormat.parser();
if (registry != null)
	jFormatter = jFormatter.usingTypeRegistry(registry);
jFormatter.merge(json.toString(), builder);
ClassificationRequest request = builder.build();
return request;
  }
 
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:18,代码来源:ClientRpcStore.java


示例2: testDatastoreToGcs_EntityToJson_noTransform

import com.google.protobuf.util.JsonFormat.TypeRegistry; //导入依赖的package包/类
@Test
public void testDatastoreToGcs_EntityToJson_noTransform() throws Exception {
  DoFnTester<Entity, String> fnTester = DoFnTester.of(EntityToJson.newBuilder()
      .setJsTransformPath(StaticValueProvider.of(null))
      .setJsTransformFunctionName(StaticValueProvider.of(null))
      .build());

  Builder entityBuilder = Entity.newBuilder();
  JsonFormat.parser().usingTypeRegistry(
      TypeRegistry.newBuilder()
          .add(Entity.getDescriptor())
          .build())
      .merge(mEntityJson, entityBuilder);

  Entity entity = entityBuilder.build();
  List<String> entityJsonOutputs = fnTester.processBundle(entity);
  Assert.assertEquals(mEntityJson, entityJsonOutputs.get(0));
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:19,代码来源:DatastoreToGcsTest.java


示例3: testDatastoreToGcs_EntityToJson_withTransform

import com.google.protobuf.util.JsonFormat.TypeRegistry; //导入依赖的package包/类
@Test
public void testDatastoreToGcs_EntityToJson_withTransform() throws Exception {
  DoFnTester<Entity, String> fnTester = DoFnTester.of(EntityToJson.newBuilder()
      .setJsTransformPath(StaticValueProvider.of(jsTransformPath))
      .setJsTransformFunctionName(StaticValueProvider.of("transform"))
      .build());

  Builder entityBuilder = Entity.newBuilder();
  JsonFormat.parser().usingTypeRegistry(
      TypeRegistry.newBuilder()
          .add(Entity.getDescriptor())
          .build())
      .merge(mEntityJson, entityBuilder);

  Entity entity = entityBuilder.build();
  List<String> entityJsonOutputs = fnTester.processBundle(entity);
  Assert.assertEquals(mTransformedEntityJson, entityJsonOutputs.get(0));
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:19,代码来源:DatastoreToGcsTest.java


示例4: testGcsToDatastore_EntityToJson_noTransform

import com.google.protobuf.util.JsonFormat.TypeRegistry; //导入依赖的package包/类
@Test
public void testGcsToDatastore_EntityToJson_noTransform() throws Exception {
  DoFnTester<String, Entity> fnTester = DoFnTester.of(JsonToEntity.newBuilder()
      .setJsTransformPath(StaticValueProvider.of(null))
      .setJsTransformFunctionName(StaticValueProvider.of(null))
      .build());
  List<Entity> output = fnTester.processBundle(mEntityJson);
  Entity outputEntity = output.get(0);

  Printer printer = JsonFormat.printer()
      .omittingInsignificantWhitespace()
      .usingTypeRegistry(
          TypeRegistry.newBuilder()
              .add(Entity.getDescriptor())
              .build());
  Assert.assertEquals(mEntityJson, printer.print(outputEntity));
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:18,代码来源:GcsToDatastoreTest.java


示例5: testDatastoreToBq_EntityToTableRow_notransform

import com.google.protobuf.util.JsonFormat.TypeRegistry; //导入依赖的package包/类
@Test
public void testDatastoreToBq_EntityToTableRow_notransform() throws Exception, IOException {
  DoFnTester<Entity, TableRow> fnTester = DoFnTester.of(EntityToTableRow.newBuilder()
      .setStrictCast(StaticValueProvider.of(true))
      .setTableSchemaJson(StaticValueProvider.of(mTableSchemaJson))
      .setJsTransformFunctionName(StaticValueProvider.of(null))
      .setJsTransformPath(StaticValueProvider.of(null))
  .build());

  Builder entityBuilder = Entity.newBuilder();
  JsonFormat.parser().usingTypeRegistry(
      TypeRegistry.newBuilder()
          .add(Entity.getDescriptor())
          .build())
      .merge(mEntityJson, entityBuilder);

  Entity entity = entityBuilder.build();
  List<TableRow> tableRows = fnTester.processBundle(entity);
  TableRow tr = tableRows.get(0);

  Assert.assertEquals(1, tableRows.size());
  Assert.assertEquals("key(Drawing, '31ce830e-91d0-405e-855a-abe416cadc1f')", tr.get("__key__"));
  Assert.assertEquals("79a1d9d9-e255-427a-9b09-f45157e97790", tr.get("canvasId"));
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:25,代码来源:DatastoreToBqTest.java


示例6: getDefaultRequestJSON

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


示例7: getPredictReplyFromJson

import com.google.protobuf.util.JsonFormat.TypeRegistry; //导入依赖的package包/类
public ClassificationReply getPredictReplyFromJson(String client,JsonNode json)
{
	RPCConfig config = services.get(client);
	try
	{
		TypeRegistry registry = null;
		if (config != null && config.replyClass != null && json.has(PredictionBusinessServiceImpl.REPLY_CUSTOM_DATA_FIELD))
		{
			if (!json.get(PredictionBusinessServiceImpl.REPLY_CUSTOM_DATA_FIELD).has("@type"))
				((ObjectNode) json.get(PredictionBusinessServiceImpl.REPLY_CUSTOM_DATA_FIELD)).put("@type", "type.googleapis.com/" + config.replyClass.getName());
			Method m = config.replyBuilder;
			Message.Builder o = (Message.Builder) m.invoke(null);
			registry = TypeRegistry.newBuilder().add(o.getDescriptorForType()).build();
		}
		ClassificationReply.Builder builder = ClassificationReply.newBuilder();
		JsonFormat.Parser jFormatter = JsonFormat.parser();
		if (registry != null)
			jFormatter = jFormatter.usingTypeRegistry(registry);
		jFormatter.merge(json.toString(), builder);
		ClassificationReply reply = builder.build();
		return reply;
	} catch (Exception e) {
		logger.error("Failed to convert json "+json.toString()+" to PredictReply",e);
		return null;
	}
}
 
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:27,代码来源:ClientRpcStore.java


示例8: getJsonPrinter

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


示例9: getJsonParser

import com.google.protobuf.util.JsonFormat.TypeRegistry; //导入依赖的package包/类
private JsonFormat.Parser getJsonParser() {
  if (mJsonParser == null) {
    TypeRegistry typeRegistry = TypeRegistry.newBuilder()
        .add(Entity.getDescriptor())
        .build();

    mJsonParser = JsonFormat.parser()
        .usingTypeRegistry(typeRegistry);
  }
  return mJsonParser;
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:12,代码来源:GcsToDatastore.java


示例10: addPlatformExtensions

import com.google.protobuf.util.JsonFormat.TypeRegistry; //导入依赖的package包/类
private TypeRegistry.Builder addPlatformExtensions(TypeRegistry.Builder registryBuilder) {
  ExtensionRegistry extensions = ToolProtoUtil.getStandardPlatformExtensions();
  for (String extendedType : EXTENDED_ELEMENTS) {
    for (ExtensionRegistry.ExtensionInfo info :
        extensions.getAllImmutableExtensionsByExtendedType(extendedType)) {

      if (null != info.defaultInstance) {
        registryBuilder.add(info.defaultInstance.getDescriptorForType());
      }
    }
  }
  return registryBuilder;
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:14,代码来源:ConfigGeneratorDriver.java


示例11: createPrinter

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


示例12: createParser

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

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


示例13: getJSONFromMethod

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


示例14: testParseFromJSON

import com.google.protobuf.util.JsonFormat.TypeRegistry; //导入依赖的package包/类
@Test
public void testParseFromJSON() throws InvalidProtocolBufferException
{
	String json = "{\"meta\":{\"modelName\":\"some-name\"},\"custom\":{\"@type\":\"type.googleapis.com/io.seldon.api.rpc.example.CustomPredictReply\",\"data\":\"some custom data\"}}";
	ClassificationReply.Builder builder = ClassificationReply.newBuilder();
	CustomPredictReply.Builder customBuilder = CustomPredictReply.newBuilder();
	TypeRegistry registry = TypeRegistry.newBuilder().add(customBuilder.getDescriptorForType()).build();
	JsonFormat.Parser jFormatter = JsonFormat.parser().usingTypeRegistry(registry);
	jFormatter.merge(json, builder);
	ClassificationReply reply = builder.build();
	System.out.println(reply);
}
 
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:13,代码来源:CustomClassTest.java


示例15: testParseFromJSONDefault

import com.google.protobuf.util.JsonFormat.TypeRegistry; //导入依赖的package包/类
@Test
public void testParseFromJSONDefault() throws InvalidProtocolBufferException
{
	String json = "{\"data\":{\"@type\":\"type.googleapis.com/io.seldon.api.rpc.DefaultCustomPredictRequest\",\"values\":[1.2,2.1]}}";
	ClassificationRequest.Builder builder = ClassificationRequest.newBuilder();
	DefaultCustomPredictRequest.Builder customBuilder = DefaultCustomPredictRequest.newBuilder();
	TypeRegistry registry = TypeRegistry.newBuilder().add(customBuilder.getDescriptorForType()).build();
	JsonFormat.Parser jFormatter = JsonFormat.parser().usingTypeRegistry(registry);
	jFormatter.merge(json, builder);
	ClassificationRequest request = builder.build();
	System.out.println(request);
}
 
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:13,代码来源:CustomClassTest.java


示例16: dump

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


示例17: assertRoundTripEquals

import com.google.protobuf.util.JsonFormat.TypeRegistry; //导入依赖的package包/类
private void assertRoundTripEquals(Message message, TypeRegistry registry) throws Exception {
  JsonFormat.Printer printer = JsonFormat.printer().usingTypeRegistry(registry);
  JsonFormat.Parser parser = JsonFormat.parser().usingTypeRegistry(registry);
  Message.Builder builder = message.newBuilderForType();
  parser.merge(printer.print(message), builder);
  Message parsedMessage = builder.build();
  assertEquals(message.toString(), parsedMessage.toString());
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:9,代码来源:JsonFormatTest.java


示例18: testEmptyWrapperTypesInAny

import com.google.protobuf.util.JsonFormat.TypeRegistry; //导入依赖的package包/类
public void testEmptyWrapperTypesInAny() throws Exception {
  JsonFormat.TypeRegistry registry =
      JsonFormat.TypeRegistry.newBuilder().add(TestAllTypes.getDescriptor()).build();
  JsonFormat.Parser parser = JsonFormat.parser().usingTypeRegistry(registry);

  Any.Builder builder = Any.newBuilder();
  parser.merge(
      "{\n"
          + "  \"@type\": \"type.googleapis.com/google.protobuf.BoolValue\",\n"
          + "  \"value\": false\n"
          + "}\n",
      builder);
  Any any = builder.build();
  assertEquals(0, any.getValue().size());
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:16,代码来源:JsonFormatTest.java


示例19: run

import com.google.protobuf.util.JsonFormat.TypeRegistry; //导入依赖的package包/类
public void run() throws Exception {
  typeRegistry = TypeRegistry.newBuilder().add(
      TestMessagesProto3.TestAllTypesProto3.getDescriptor()).build();
  while (doTestIo()) {
    this.testCount++;
  }

  System.err.println("ConformanceJava: received EOF from test runner after " +
      this.testCount + " tests");
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:11,代码来源:ConformanceJava.java


示例20: valueToString

import com.google.protobuf.util.JsonFormat.TypeRegistry; //导入依赖的package包/类
@Nullable
private String valueToString(Value v) throws IOException {
  if (strictCast() && !v.getValueTypeCase().equals(ValueTypeCase.STRING_VALUE)) {
    return null;
  }

  switch (v.getValueTypeCase()) {
    case STRING_VALUE:
      return v.getStringValue();
    case INTEGER_VALUE:
      return Long.toString(v.getIntegerValue());
    case DOUBLE_VALUE:
      return Double.toString(v.getDoubleValue());
    case BOOLEAN_VALUE:
      return Boolean.toString(v.getBooleanValue());
    case TIMESTAMP_VALUE:
      return valueToTimestamp(v);
    case NULL_VALUE:
      return null;
    case BLOB_VALUE:
      return valueToBytes(v);
    case ARRAY_VALUE:
      ArrayList<String> arr = new ArrayList<>();
      for (Value av: v.getArrayValue().getValuesList()) {
        arr.add(valueToString(av));
      }
      return Transport.getJsonFactory().toString(arr);
    case ENTITY_VALUE:
      try {
        return JsonFormat.printer()
            .usingTypeRegistry(TypeRegistry.newBuilder()
                .add(Entity.getDescriptor())
                .build())
            .omittingInsignificantWhitespace()
            .print(v.getEntityValue());
      } catch (InvalidProtocolBufferException e) {
        e.printStackTrace();
        return null;
      }
    case GEO_POINT_VALUE:
      return valueToGeopoint(v);
    case KEY_VALUE:
      return keyToString(v.getKeyValue());
    default:
      throw new IllegalArgumentException(
          "ValueType Case not handled: " + v.getValueTypeCase());
  }
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:49,代码来源:EntityBQTransform.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NameValueExpression类代码示例发布时间:2022-05-23
下一篇:
Java PartitionNode类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap