-
I have an Express server with Connect set up, which, among other things, receives files and their contents from users and writes them to the server's FS. message FileEdit {
string path = 1;
google.protobuf.Value content = 2;
}
message EditFilesRequest {
repeated FileEdit file_edits = 1;
} When using a cURL, I can just send the curl \
--header 'Content-Type: application/json' \
--data '{"file_edits":[{"path": "example.json","content": { "a": { "b": 2, "c": [1, "2", []]}, "d": 2 }}]} \
http://.../EditFiles However, when using the Node Connect client I have to serialize it myself using import { client } from 'my-client.ts'
import { Value } from '@bufbuild/protobuf';
await client.editFiles({
file_edits: [{ path: 'example.json', content: Value.fromJson({ a: { b: 2, c: [1, '2', []] }, d: 2 }) }],
}); Is there any way I can just send the content as JSON, and let Connect itself take care of serializing it to the correct format (same as in cURL)? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hadar, for the well-known wrappers.proto, we already "unbox" to an optional primitive in the generated code: /**
* @generated from field: google.protobuf.BoolValue bool_value_field = 1;
*/
boolValueField?: boolean; We could take a similar approach with /**
* @generated from field: google.protobuf.Value content = 2;
*/
content?: JsonValue; Would you like to add a feature request in protobuf-es? It's a breaking change, and we might not get to it right away, but it definitely looks like a good improvement. |
Beta Was this translation helpful? Give feedback.
Hadar, for the well-known wrappers.proto, we already "unbox" to an optional primitive in the generated code:
We could take a similar approach with
google.protobuf.Value
(and alsogoogle.protobuf.Struct
, a JSON object). For your example, it would be:Would you like to add a feature request in protobuf-es? It's a breaking change, and we might not get to it right away, but it definitely looks like a good improvement.