Skip to content

Deprecate Js_json's serializeExn and deserializeUnsafe #5451

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

Closed
ryyppy opened this issue Jun 20, 2022 · 1 comment
Closed

Deprecate Js_json's serializeExn and deserializeUnsafe #5451

ryyppy opened this issue Jun 20, 2022 · 1 comment

Comments

@ryyppy
Copy link
Member

ryyppy commented Jun 20, 2022

Json.serializeExn and Json.deserializeUnsafe were introduced to allow string serialization of records that contain option values.

E.g.

let user = {
  name: "test",
  age: None
}

would compile to { name: "test", age: undefined} — a JS object that's not stringifiable due to the undefined value (which is not part of the JSON spec).

This was particularly an issue in Next, when using specific features like SSR to inject initial props (see #4443 for the full discussion).

Now with our new @optional feature (#5423) this is not needed anymore, since I would just declare a prop type as followed:

type user = {
  name: string,
 @optional age: int
}

Later on I'd just omit the age and be good to go. No undefined values in the output:

let user = {name: "patrick"}

// Equal to `{name: "patrick"}` in JS

My suggestion is to add a deprecation notice and point to the new docs of the @optional feature instead. Any opinions?

@ryyppy ryyppy modified the milestone: v10.0 Jun 20, 2022
@ryyppy
Copy link
Member Author

ryyppy commented Jun 20, 2022

After some discussions with @cristianoc, it's probably better to wait a little longer until we move on with this. Will still keep it around for later reference.

@ryyppy ryyppy closed this as completed Jun 22, 2022
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

1 participant