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

Fix bug deserializing jsonrpc version from Value #209

Merged
merged 1 commit into from
Aug 11, 2020

Conversation

ebkalderon
Copy link
Owner

Fixed

  • Fix deserialization bug breaking serde_json::from_value support for jsonrpc::{Incoming,Outgoing} messages.

It turns out that serde_json::from_value always provides an owned String to the deserializer instead of a borrowed str as previously assumed. This means that while serde_json::from_str works fine, deserializing with serde_json::from_value fails with the following error:

invalid type: string "2.0", expected a borrowed string

Changing jsonrpc::Version to deserialize the string into a Cow<'de, str> instead of a plain str fixes this problem.

Bug was first identified in wasm-lsp/wasm-lsp-server#47 (comment).

Sorry for the breakage, @darinmorrison! ❤️

It turns out that `serde_json::from_value` always provides an owned
`String` to the deserializer instead of a borrowed `str` as previously
assumed. This means that while `serde_json::from_str` works fine,
deserializing with `serde_json::from_value` fails with the following
error:

```
invalid type: string "2.0", expected a borrowed string
```

Changing `jsonrpc::Version` to deserialize the string into a
`Cow<'de, str>` instead of a plain `str` fixes this problem.
@ebkalderon ebkalderon self-assigned this Aug 11, 2020
@ebkalderon ebkalderon merged commit cee377f into master Aug 11, 2020
@ebkalderon ebkalderon deleted the fix-version-deserialize-bug branch August 11, 2020 02:29
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

Successfully merging this pull request may close these issues.

1 participant