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

Add note about toJSON to the migration guide #980

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2341,17 +2341,18 @@ function show(user: User) {
}
```

Note that messages also no longer implement the special method `toJSON`. Before you pass a message to `JSON.stringify`,
convert it to a JSON value first (using `toJson`).

The generated properties remain largely unchanged. There are two improvements:

- A message field using [`google.protobuf.Struct`](#googleprotobufstruct) is generated as `JsonObject`.
- Proto2 fields support [default values](#field-presence-and-default-values) now and are no longer generated as optional properties.

The `toPlainMessage` function and the `PlainMessage<T>` type are no longer necessary. If you create a proto3 message with
`create(UserSchema)`, the returned object is already a plain object.

You can replace the `PlainMessage<User>` type with `User`. The only difference is that `User` has a property
`$typeName`, which is a simple string with the full name of the message like `"example.User"`.
This property makes sure you don't pass the wrong message to a function by accident.
`create(UserSchema)`, the returned object is already a plain object. You can replace the `PlainMessage<User>` type with
`User`. The only difference is that `User` has a property `$typeName`, which is a simple string with the full name of
the message like `"example.User"`. This property makes sure you don't pass the wrong message to a function by accident.

[Well-known types](#well-known-types) have moved to a subpath export `@bufbuild/protobuf/wkt`.

Expand Down