Closed kzolti closed 5 months ago
Sorry for the delay. You are correct that fromObject
works and is essentially just disconnected. However, this is intentional (our internal codebase essentially has a do-not-export ifdef around it.
We generally don't support toObject/fromObject aside from testing convenience. The produced object format is not stable and should not be used by applications in production. I can't speak for other bundlers, but I know the Closure Compiler in particular will minify the object keys and cause issues between debug/prod builds.
If there particular reason you want this instead of using serialization/deserialization?
We generally don't support toObject/fromObject aside from testing convenience. The produced object format is not stable and should not be used by applications in production. I can't speak for other bundlers, but I know the Closure Compiler in particular will minify the object keys and cause issues between debug/prod builds.
If there particular reason you want this instead of using serialization/deserialization?
The fromObject
method provides a straightforward way to convert JavaScript objects to Protobuf messages, reducing boilerplate code.
I use React. The fromObject
works reliably in React applications. The potential issues with the Closure Compiler are not relevant to React, which does not use this tool.
By merging this pull request, the protobuf-javascript
library will gain a long-requested feature that improves developer experience and productivity in modern web applications.
I know there's an FR around this, but as some of the original comments noted, to/fromObject is distinct from standard proto3 JSON (I can't speak off the top of my head to the precise differences). Hypothetically, proto3 JSON is something we would want to support.
We don't support to/fromObject internally. It just exists because of inertia and generally causes us frustration as maintainers. Since it's not presently available in open source, we don't want to start providing it.
The fromObject method works without errors.