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

RFC: Implementing multiple serialization methods #1197

Open
lukepighetti opened this issue Nov 6, 2022 · 1 comment
Open

RFC: Implementing multiple serialization methods #1197

lukepighetti opened this issue Nov 6, 2022 · 1 comment

Comments

@lukepighetti
Copy link

lukepighetti commented Nov 6, 2022

Sometimes you want to serialize a data class into multiple different data formats. The most common is JSON, but others include MessagePack, protobuf, XML, custom binary payloads, and more.

Serde (for Rust) has a list of data formats that are supported through external plugins. https://serde.rs/#data-formats

It would be nice to have some examples of how to handle serialization with built_value to multiple data formats.

I noticed we have StandardJsonPlugin, but it's not clear to me how we could use that and something like a MessagePackPlugin simultaneously, especially since @BuiltValue only supports String wire names, and it's not clear how we would input more complex information (especially in the case of binary formats). I suspect we'd have to duplicate the serializer stack and have different plugins on each one?

(I would have opened this as a discussion but I noticed it's not enabled on this repo!)

@dave26199
Copy link

Hi Luke,

The simplest thing would be if the existing serialized format can be mapped to the additional format(s). Note that it does not actually serialize to JSON strings, but to a List (the default format) or Map (with StandardJsonPlugin). These structures may be easy to convert to other serialization formats.

I guess the most important consideration is whether there is enough information present to convert to each serialization format. Obviously if something is missing that could only be added by the developer or deduced during codegen then that will need special support.

Broadly speaking I would be open to adding more general support / hooks to support new ways of serialization--as long as they do not turn out to be too far off the path of what built_value is already doing. There is a case for limiting codegen complexity and a case for limiting any unused output of the codegen. On the other hand, I've thought for a while that the existing mechanism is probably not general enough and it would be nice to refactor on top of a more general core.

Did you have any specific format(s) in mind that you'd like to see supported? That might make the discussion more concrete :)

Thanks.

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

No branches or pull requests

2 participants