Unable to use custom JsonFormat.Printer for ProtobufResponseConverterFunction
See original GitHub issueHello, we’re trying to use in a custom com.google.protobuf.util.JsonFormat.Printer for the ProtobufResponseConverterFunction , which we are using to convert the HttpResult from our endpoint into JSON
We’re doing this by passing in a custom instance of the converter function like so:
serverBuilder.annotatedService(myService, ProtobufResponseConverterFunction(JsonFormat.printer().includingDefaultValueFields())))
However, the custom Printer isn’t being used. It looks like a new converter is being instantiated along the way, which results in the Printer passed in to be ignored
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:20 (20 by maintainers)
Top Results From Across the Web
JsonFormat.Printer serializes custom options, but ... - GitHub
JsonFormat.Printer serializes custom options, but JsonFormat.Parser fails to deserialize them #7223.
Read more >JsonFormat.Printer - Google Developers
A Printer converts protobuf message to JSON format. ... Printer that is configured to use the original proto field names as defined in...
Read more >JsonFormat.printer().print() doesn't accept my Message
If I want to apply JsonFormat.printer().print() to one of my Message, the project doesn't compile and the method is underlined in red: ...
Read more >Class JsonFormat.Printer | Java client library - Google Cloud
A Printer converts protobuf message to JSON format. ... Creates a new Printer that is configured to use the original proto field names...
Read more >JsonFormat.Printer (Protocol Buffers [Util] 3.0.2 API) - javadoc.io
A Printer converts protobuf message to JSON format. ... Printer that is configured to use the original proto field names as defined in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Let’s say we have the following annotated service:
We need two 2 response converters to completely convert
Flow<MyProtobuf>into a JSON response. First,MyProtobufResponseConverterwill be used to convert eachMyProtobufinto a JSON object. Next,FlowResponseConverterFunctionshould be chosen to collect the JSON objects and convert them into a JSON array.Currently, we provide two APIs for a custom response converter.
ResponseConverterFunctiondefines how to convert an object.ResponseConverterFunctionProviderdefines how to create aResponseConverterFunctionvia SPI.The downside of the APIs is that they don’t tell a
ResponseConverterFunctionis a primitive converter or a delegatingResponseConverterFunction. It is difficult to prioritize between them. So we’d like to change our API to show their explicit behavior. Note: As the API is@UnstableApi, we can still make a breaking change. 😅Proposal:
ResponseConverterFunctionProviderto two providers.DelegatingResponseConverterFunctionProviderrequires a delegate to complete to convert a response likeFlowResponseConverterFunctionand the newResponseConverterFunctionProviderdoes not take any parameters.ResponseConverterFunctionProviderthat create a primitiveResponseConverterFunctionwhich converters an object to anHttpResponsewithout depending on otherResponseConverterFunctions.DelegatingResponseConverterFunctionProviderhas higher priority than primitive converters. Because it needs primitive converters to create a delegating response converter.Just for clarification:
By this, I think we mean that we will define the behavior of
armeria’s defaultResponseConverterFunctionProviderimplementation such that it returns a function:responseConverterFunctionresponseConverterFunctionfalls through, theResponseConverterFunctionProviderwill try to apply its ownResponseConverterFunctionso I guess the PR would look roughly like follows (the same would be applied to
ScalaPbResponseConverterFunctionProvider):I wanted to make sure I also understood @minwoox 's comments correctly 😅