com.google.protobuf.util.JsonFormat.Printer Java Examples
The following examples show how to use
com.google.protobuf.util.JsonFormat.Printer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestConfig.java From kbear with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) private ProtobufHttpMessageConverter newCustomProtobufMessageConverter() throws Exception { Constructor[] constructors = ProtobufHttpMessageConverter.class.getDeclaredConstructors(); Constructor requiredConstructor = null; for (Constructor constructor : constructors) { if (constructor.getParameterTypes().length == 2) { constructor.setAccessible(true); requiredConstructor = constructor; break; } } Class[] classes = ProtobufHttpMessageConverter.class.getDeclaredClasses(); Class requiredClass = null; for (Class clazz : classes) { if (clazz.getSimpleName().equals("ProtobufJavaUtilSupport")) { requiredClass = clazz; break; } } Constructor pbUtilSupportConstructor = requiredClass.getConstructor(Parser.class, Printer.class); pbUtilSupportConstructor.setAccessible(true); Parser parser = JsonFormat.parser().ignoringUnknownFields(); Printer printer = JsonFormat.printer().includingDefaultValueFields().preservingProtoFieldNames() .omittingInsignificantWhitespace(); Object support = pbUtilSupportConstructor.newInstance(parser, printer); return (ProtobufHttpMessageConverter) requiredConstructor.newInstance(support, null); }
Example #2
Source File: LoggerDoFn.java From feast with Apache License 2.0 | 5 votes |
@ProcessElement public void processElement(ProcessContext context) { Printer printer = JsonFormat.printer().omittingInsignificantWhitespace(); String message; try { message = prefix + printer.print(context.element()); } catch (Exception e) { log.error(e.getMessage(), e); message = prefix + context.element().toString(); } switch (level) { case INFO: log.info(message); break; case ERROR: log.error(message); break; case WARN: log.warn(message); break; case DEBUG: log.debug(message); break; case TRACE: log.trace(message); break; } }
Example #3
Source File: JsonMarshaller.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
/** * Create a {@code Marshaller} for json protos of the same type as {@code defaultInstance}. * * <p>This is an unstable API and has not been optimized yet for performance. */ public static <T extends Message> Marshaller<T> jsonMarshaller(final T defaultInstance) { final Parser parser = JsonFormat.parser(); final Printer printer = JsonFormat.printer(); return jsonMarshaller(defaultInstance, parser, printer); }
Example #4
Source File: MessageWriter.java From grpc-swagger with MIT License | 4 votes |
private MessageWriter(Printer printer, CallResults results) { this.printer = printer; this.results = results; }
Example #5
Source File: DirectRunnerJobManagerTest.java From feast with Apache License 2.0 | 4 votes |
@Test public void shouldStartDirectJobAndRegisterPipelineResult() throws IOException { StoreProto.Store store = StoreProto.Store.newBuilder() .setName("SERVING") .setType(StoreType.REDIS) .setRedisConfig(RedisConfig.newBuilder().setHost("localhost").setPort(6379).build()) .addSubscriptions(Subscription.newBuilder().setProject("*").setName("*").build()) .build(); SourceProto.Source source = SourceProto.Source.newBuilder() .setType(SourceType.KAFKA) .setKafkaSourceConfig( KafkaSourceConfig.newBuilder() .setTopic("topic") .setBootstrapServers("servers:9092") .build()) .build(); FeatureSetProto.FeatureSet featureSet = FeatureSetProto.FeatureSet.newBuilder() .setSpec( FeatureSetSpec.newBuilder() .setName("featureSet") .setMaxAge(Duration.newBuilder()) .setSource(source) .build()) .build(); Printer printer = JsonFormat.printer(); String expectedJobId = "feast-job-0"; ImportOptions expectedPipelineOptions = PipelineOptionsFactory.fromArgs("").as(ImportOptions.class); expectedPipelineOptions.setJobName(expectedJobId); expectedPipelineOptions.setAppName("DirectRunnerJobManager"); expectedPipelineOptions.setRunner(DirectRunner.class); expectedPipelineOptions.setBlockOnRun(false); expectedPipelineOptions.setTargetParallelism(1); expectedPipelineOptions.setStoresJson(Lists.newArrayList(printer.print(store))); expectedPipelineOptions.setProject(""); expectedPipelineOptions.setSourceJson(printer.print(source)); ArgumentCaptor<ImportOptions> pipelineOptionsCaptor = ArgumentCaptor.forClass(ImportOptions.class); ArgumentCaptor<DirectJob> directJobCaptor = ArgumentCaptor.forClass(DirectJob.class); PipelineResult mockPipelineResult = Mockito.mock(PipelineResult.class); doReturn(mockPipelineResult).when(drJobManager).runPipeline(any()); Job job = Job.builder() .setId(expectedJobId) .setExtId("") .setRunner(Runner.DIRECT) .setSource(Source.fromProto(source)) .setStores(ImmutableSet.of(Store.fromProto(store))) .setFeatureSetJobStatuses(makeFeatureSetJobStatus(FeatureSet.fromProto(featureSet))) .setStatus(JobStatus.PENDING) .build(); Job actual = drJobManager.startJob(job); verify(drJobManager, times(1)).runPipeline(pipelineOptionsCaptor.capture()); verify(directJobRegistry, times(1)).add(directJobCaptor.capture()); assertThat(actual.getStatus(), equalTo(JobStatus.RUNNING)); ImportOptions actualPipelineOptions = pipelineOptionsCaptor.getValue(); DirectJob jobStarted = directJobCaptor.getValue(); expectedPipelineOptions.setOptionsId( actualPipelineOptions.getOptionsId()); // avoid comparing this value assertThat( actualPipelineOptions.getDeadLetterTableSpec(), equalTo(expectedPipelineOptions.getDeadLetterTableSpec())); assertThat( actualPipelineOptions.getStatsdHost(), equalTo(expectedPipelineOptions.getStatsdHost())); assertThat( actualPipelineOptions.getMetricsExporterType(), equalTo(expectedPipelineOptions.getMetricsExporterType())); assertThat( actualPipelineOptions.getStoresJson(), equalTo(expectedPipelineOptions.getStoresJson())); assertThat( actualPipelineOptions.getSourceJson(), equalTo(expectedPipelineOptions.getSourceJson())); assertThat( actualPipelineOptions.getSpecsStreamingUpdateConfigJson(), equalTo(printer.print(specsStreamingUpdateConfig))); assertThat(jobStarted.getPipelineResult(), equalTo(mockPipelineResult)); assertThat(jobStarted.getJobId(), equalTo(expectedJobId)); assertThat(actual.getExtId(), equalTo(expectedJobId)); }
Example #6
Source File: MessageWriter.java From grpc-swagger with MIT License | 4 votes |
private MessageWriter(Printer printer, CallResults results) { this.printer = printer; this.results = results; }
Example #7
Source File: JsonMarshaller.java From grpc-java with Apache License 2.0 | 4 votes |
/** * Create a {@code Marshaller} for json protos of the same type as {@code defaultInstance}. * * <p>This is an unstable API and has not been optimized yet for performance. */ public static <T extends Message> Marshaller<T> jsonMarshaller(final T defaultInstance) { final Parser parser = JsonFormat.parser(); final Printer printer = JsonFormat.printer(); return jsonMarshaller(defaultInstance, parser, printer); }