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

Support serializing strings containing lone surrogates with deserialize_any #890

Open
lucacasonato opened this issue May 18, 2022 · 0 comments

Comments

@lucacasonato
Copy link
Contributor

lucacasonato commented May 18, 2022

Usually serde_json can deserialize JSON strings into byte buffers, which makes deserializing JSON with lone surrogate pairs (which are valid JSON), possible (see #828).

Unfortunately, this is not possible when serde_json is driving the deserialization visitor, i.e. with deserialize_any. To my knowledge this makes it impossible to deserialize unknown JSON values while not erroring on lone surrogates using serde_json.

I understand this is rather contrived, but it'd be great to figure out a solution to this. I am not really sure how though. My best idea is to add a way for visitors to tell the Deserializer what visitation types it supports/prefers, so the Deserializer can make informed decisions about how to handle data types that can be deserialized in multiple ways in deserialize_any. This could look something like this:

type VisitationType {
  Bool,
  Unsigned,
  Signed,
  Float,
  Char,
  String,
  Bytes,
  Unit,
  Option,
  NewtypeStruct,
  Seq,
  Map,
  Enum,
}

pub trait Visitor<'de>: Sized {
  ...

  /// Hint to the deserializer what types this visitor supports, for when the
  /// deserializer is driving the visitor autonomously using `deserialize_any`.
  ///
  /// This is only a hint. Deserializers are not required to respect the preference.
  fn preferred_types(&self) -> Option<&[VisitationType]> {
    Some(&[])
  }
}

This would require a change to serde though, which may not be desirable or possible.

I'd love to hear feedback on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant