Code Monkey home page Code Monkey logo

Comments (1)

helixbass avatar helixbass commented on September 22, 2024

Sniffing at eg the output of cargo expand, it looks like the basic reason this is happening is because the derived Deserialize implementations for untagged/internally-tagged enums use .deserialize_any() (+ Content?) which has to sort of "blindly" decide what to do with a JSON string that it encounters, and so understandably defaults to trying to deserialize it as a "string" (vs as "bytes")

So I'm assuming this should not be considered a "bug" of any kind but am curious if there are known strategies that would enable using serde/serde_json to deserialize eg internally-tagged enums with fields that may contain unpaired surrogates?

The two general ideas that I can picture are:

  1. Have like an alternate version of serde_json whose .deserialize_any() defaults to treating JSON strings as bytes, not as strings
  2. If you know that your "tag" field should come first in the JSON (which I think is a safe assumption/invariant in my use case) then it seems like you could defer deserializing the rest of the JSON object keys/values until after you've deserialized/"recognized" the tag field (at which point you could then avoid using .deserialize_any() because you'd know which enum variant you were deserializing, similar to how I'm assuming that "externally tagged" enums apparently avoid this issue)?

from json.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.