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

#[serde(untagged)] doesn't work with RawValue #296

Closed
Tracked by #416
dvdplm opened this issue Apr 30, 2021 · 1 comment · Fixed by #419 or #420
Closed
Tracked by #416

#[serde(untagged)] doesn't work with RawValue #296

dvdplm opened this issue Apr 30, 2021 · 1 comment · Fixed by #419 or #420
Labels
enhancement New feature or request

Comments

@dvdplm
Copy link
Contributor

dvdplm commented Apr 30, 2021

For reasons outlined here, RawValue can't be
used with untagged enums at the moment.
This means we can't use an SingleOrBatch untagged enum to handle incoming requests that can be one of:

  • single JSONRPC request, i.e. {"jsonrpc":"2.0","method":"bar","id":1}
  • a batch of requests, i.e. [{"jsonrpc":"2.0","method":"baz","id":1}, {"jsonrpc":"2.0","method":"baz","id":2}]
  • a single notification, i.e. {"jsonrpc":"2.0","method":"bezz"}
  • a batch of notifications, i.e. [{"jsonrpc":"2.0","method":"bezz"}, {"jsonrpc":"2.0","method":"bozz"}, {"jsonrpc":"2.0","method":"bizz"}]

(We do not support notifications, but if we ever were to do that to be fully compliant with the spec, this problem would make things worse)

Instead we have to try each case individually: first the single request case, then the batch case and then one time more to check for the error. For the worst case – unparseable input – we make three calls to [serde_json::from_slice] which is pretty annoying.

There is a PoC fix for this in serde-rs/serde#1354

Suggestion: revisit this when/if serde-rs/serde#1354 lands.

@dvdplm dvdplm added the enhancement New feature or request label May 21, 2021
@dvdplm
Copy link
Contributor Author

dvdplm commented Jul 14, 2021

A possible workaround here is to do what @maciejhirsz did with the optional params parsing: check the first byte for a [ (batch).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant