-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot encode message google.protobuf.Any in the v2.0.0-alpha #1192
Comments
Hey @biziosan, thanks for giving the alpha a try!
In the JSON format, So to serialize There is a simple solution to the problem: You can create a registry with the types you want to allow for import { createRegistry } from "@bufbuild/protobuf";
import { connectNodeAdapter } from "@connectrpc/connect";
connectNodeAdapter({
routes,
jsonOptions: {
registry: createRegistry(TestObjectSchema),
},
});
|
Hi @timostamm, thank you for this new version! I am looking forward to working with it. Thank you for looking at this issue. I made the changes you suggested (the new code is below), and it works now! I added the registry for both the encode and decode sides. In my main application, I already have the full registry, so I will give it to the JSON options. function createServer()
{
const rpcHandler = cnrpc.connectNodeAdapter(
{
routes: function(router: crpc.ConnectRouter) {
router.service(TestService, {
requestTest(request: TestRequest): TestAny
{
const o = proto.create(TestObjectSchema, { n: 9 });
const a = proto_wkt.anyPack(TestObjectSchema, o);
return proto.create(TestAnySchema, { object: a });
},
});
},
jsonOptions: {
registry: proto.createRegistry(TestObjectSchema),
}
}
);
http.createServer(rpcHandler).listen(8099);
}
(async () => {
createServer();
const transport = crpc_web.createConnectTransport(
{
baseUrl: 'http://127.0.0.1:8099',
jsonOptions: {
registry: proto.createRegistry(TestObjectSchema),
}
});
const client = crpc.createPromiseClient(TestService, transport);
client.requestTest({ r: 'test' }).then((response) => {
console.log(response);
});
})(); |
See connectrpc/connect-es#1192 and #41 Signed-off-by: Timo Stamm <[email protected]>
See connectrpc/connect-es#1192 and #41 Signed-off-by: Timo Stamm <[email protected]> Signed-off-by: Steve Ayers <[email protected]>
See connectrpc/connect-es#1192 and #41 Signed-off-by: Timo Stamm <[email protected]> Signed-off-by: Steve Ayers <[email protected]>
Describe the bug
When I use google.Any in my RPC arguments I get a "[internal] cannot encode message google.protobuf.Any to JSON: "type.googleapis.com/TestObject" is not in the type registry" message when calling the RPC.
To Reproduce
Returning a non-Any message works as expected.
These are the
.proto
files used:This reduced example generates the error:
Environment (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: