-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
Provide Rust serde-like flatten behavior for flattening/sharing/capturing fields (500USD Bounty) #623
Comments
I'm taking a look at this |
I have been working on something similar ,and I think it would be good to have the following questions answered sooner or later:
case class Foo(a:Int, @flatten b:Bar)
case class Bar(a:Int) Do we allow overriding? What are the overriding rules (do we allow overriding with subclasses?) If not, how we report, do we emit compiletime errors?
case class Foo(a:Int, @flatten b:Bar)
case class Bar(@flatten c: Baz,d:String)
case class Baz(e:Int)
It might be impossible to emit compilation errors in case of generics. |
Adding another question:
sealed trait Foo
case object Bar extends Foo
case class Baz() extends Foo
case class Test(str: String, @flatten foo: Foo)
write(Bar) // "Bar"
write(Baz()) // {"$type":"Baz"}
write(Test("test", Bar)) // how would this work?
write(Test("test", Baz())) // would this be encoded like this? {"str":"test","$type":"Baz"} |
Overall I think I'd be happy with any answer to these questions, as long as the answer is documented, tested and properly justified. Some limitations are inevitable and we just need to be clear about where we draw the line and why. |
Yeah , I forgot @flatten c:Baz, will edit |
From the maintainer Li Haoyi: I'm putting a 500USD bounty on this issue, payable by bank transfer on a merged PR implementing this.
Sometimes when processing JSON you want to use a shared structure across various models. The serde crate in Rust wanted to provide support for this feature and provided it through the flatten attribute.
It would be very useful if upickle also supported this.
Lets say we have an API which supports pagination as a general concept and both our users and products endpoints support pagination.
Usecase: Sharing via Flattening
It would be useful if we could use the following models to capture this.
Usecase: Extra Fields
This can also be used as a mechanism for handling extra fields like the Rust crate also does.
The text was updated successfully, but these errors were encountered: