Comments (1)
one cannot marshal go-structs to JSON and load it in your TS code
You can! protojson.Marshal serializes your message to JSON in Go, and the method fromJsonString() parses from JSON in TS. This interoperability is a crucial feature and it definitely works reliably.
What you can't do is json.Marshal a message in Go. See the explanation in this comment:
The generation of the json tag pre-dated the formalization of the JSON<->PB specification. In it's current state, using encoding/json does not produce JSON that conforms to any particular pre-defined schema.
For similar reasons, you cannot JSON.parse()
a message in TS. Our fromJsonString()
methods use JSON.parse()
under the hood, but they also take care of field name variations and other details that protobuf and TypeScript can represent, but JSON cannot, for example NaN
. It also gives you structural validation when parsing JSON and is interoperable with all other protobuf implementations.
Closing this, but let us know if you think there's a missing piece.
from protobuf-es.
Related Issues (20)
- Oneof is not constructable in TypeScript HOT 4
- `toPlainMessage` doesn't work with RSC and messages that contain binary data (`Uint8Array`) HOT 6
- Non optional objects should be created with default values HOT 10
- `findCustomEnumOption` always returns 1 HOT 3
- Ability to generate source relative files (`paths=source_relative`) HOT 6
- All fields are optional in generated messages for proto2 schemas HOT 2
- Generated types allow assigning wrong message type if it is a superset of the target type
- out folder should be created if it does not exist HOT 2
- google.protobuf.Timestamp toDate() is not a function HOT 4
- Support the `jstype` field option HOT 7
- Why do constructors take PartialMessage only? HOT 3
- Feature request: Make opportunity to generate all in one file HOT 2
- The `FileDescriptorSet` instance omits my option HOT 3
- question: looking for a way to load a message of unknown type HOT 2
- Improve TypeScript compatibility tests
- Can't use some imports from protoplugin with Node16 resolution HOT 1
- Add CommonJS support as a plugin option HOT 12
- Investigate package-lock integrity issue HOT 6
- Q: How to use `typeRegistry.findMessage` only once? HOT 4
- Build ESM artifacts with Node16 module resolution HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf-es.