GithubHelp home page GithubHelp logo

Unions serialization. about stone HOT 7 CLOSED

dropbox avatar dropbox commented on August 20, 2024
Unions serialization.

from stone.

Comments (7)

balabuev avatar balabuev commented on August 20, 2024

Its also not understood, why simplified Union serialization (as a string value in case of void tag) is not really used (even in deserializers) in generated SDK code.
And also, its quite confusing of how to use such simplified serialization, in case of a Union inside Union.

from stone.

braincore avatar braincore commented on August 20, 2024

The .tag properties become nested under the appropriate field names. For example, given the following spec:

union U
    var1 V

union V
    varA

Serializing U outputs:

{
  ".tag": "var1",
  "var1: {
    ".tag": "varA"
  }
}

The compact union serialization format isn't understood by our client SDKs in any language besides Python because Dropbox server always sends down the more general form. That's done because we see the compact form as beneficial for writing requests by hand in a terminal, rather than for programmatic ease.

Why do we support it in Python? Because Dropbox's API servers are written in Python and the deserializers needs to support the compact form for incoming client requests: https://github.com/dropbox/stone/blob/master/stone/backends/python_rsrc/stone_serializers.py#L642

Ideally, all of our deserializers would support the compact form, but I suspect that will only happen once we/someone requires the use of a target language other than Python on their server-side.

from stone.

balabuev avatar balabuev commented on August 20, 2024

Are you sure? It seems to me that .Net SDK serializes your example as:

{
  ".tag": "var1",
  ".tag": "varA"
}

I didn't run the code, but I reviewed it. I'll check it more...

However, anyway, do unions has to inline struct fields or this is also only a compact format; for example, whether this:

union U
    var1 V

struct V
    x integer
    y integer

have to be serialized to this:

{
  ".tag": "var1",
  "x": 7,
  "y": 9
}

or general form is also valid:

{
  ".tag": "var1",
  "var1: {
    "x": 7,
    "y": 9
  }
}

from stone.

braincore avatar braincore commented on August 20, 2024

I'm certain that's our intended behavior. @qimingyuan can verify the .NET SDK.

Unions have to inline struct fields, there's no compact/general form distinction.

from stone.

balabuev avatar balabuev commented on August 20, 2024

Ok, but what about structs with subtypes? To inline their fields inside a union still two ".tag" properties are required...

from stone.

braincore avatar braincore commented on August 20, 2024

Structs with subtypes cannot be inlined. Instead, the serialization looks just like the first nested union example I provided. Let me know if you want an example.

from stone.

braincore avatar braincore commented on August 20, 2024

By the way, thanks for the feedback. I've updated our documentation to be more explicit: https://github.com/dropbox/stone/blob/master/docs/json_serializer.rst#union

Feel free to re-open if you have further questions.

from stone.

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.