Skip to content
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

Connect Web - Add Separate Models to be returned from .toJson instead of returning a JsonValue #873

Closed
seanmcquaid opened this issue Oct 6, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@seanmcquaid
Copy link

Is your feature request related to a problem? Please describe.
Presently, our team needs to utilize the .toJson method for our returned models from our auto generated services. However, we lose all semblance of references to the original model in the process. In grpc-web they have a similar method that returns a totally separate model that is a representation of the JSON returned from their method.

Describe the solution you'd like
It would be great if the .toJson method would return an auto generated model for the JSON instead of JsonValue.

@seanmcquaid seanmcquaid added the enhancement New feature or request label Oct 6, 2023
@smaye81
Copy link
Member

smaye81 commented Oct 6, 2023

Hey @seanmcquaid. Just to clarify what you're looking for here - you're trying to put a Protobuf message in a store that requires it to be a plain object that is JSON serializable, correct? If that is the case, then using toPlainMessage on the message may be your best approach. I say 'may' because you could run into issues if your schema has 64-bit integrals or bytes fields. But, if not, doing something like:

import { toPlainMessage } from "@bufbuild/protobuf";
...
const messageAsPlainType = toPlainMessage(message);

might be the best solution. You could then use the messageAsPlainType object in your store.

If you do have a schema with 64-bit integrals, then this may not work for you quite yet. However, we are going to be implementing an option that allows you to generate your 64-bit numbers as strings (see issue), so that would hopefully become a non-issue.

If none of this works for you or is not what you're looking for, we do have an issue for creating typed JSON on our radar, it's just not prioritized yet.

@seanmcquaid
Copy link
Author

Ah yes, the mentioned issue is more inline with what I'm looking for! I am good to close this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants