@Flat option annotation
See original GitHub issueI offer to include @Flat
(or @Flatten
, for example) annotation which will be used in cases when value object of field must be included directly into parent object.
@Serializable
data class Parent(
val stringField: String = "stringValue",
@Flat
val flatField: Child = Child()
)
@Serializable
class Child {
val childString: String = "childValue"
}
fun main(args: Array<String>) {
println(JSON.stringify(Parent.serializer(), Parent()))
}
Will give result:
{"stringField":"stringValue","childString":"childValue"}
Here I see a few problems:
String
and other primitives must be resolved like common fields (with their keys) or those fields must lead to exception likeIllegalArgumentException
- Collections in this case, I think, must be interpreted as associated map: with keys numbers and values - values if list
Issue Analytics
- State:
- Created 5 years ago
- Reactions:48
- Comments:6 (1 by maintainers)
Top Results From Across the Web
FLAT: FoLiA Linguistic Annotation Tool - GitHub
Flat allows users to view annotated FoLiA documents and enrich these documents with new annotations, a wide variety of linguistic annotation types is ......
Read more >FLAT User Guide — FLAT v0.5.2 documentation
The Tools & Options menu offers extra facilities for viewing. You can for instance enable the toggle Show annotator details to show who...
Read more >Annotation made easy with interactive flat panels | BenQ US
BenQ's Interactive Flat Panels Feature a Floating Tool Designed to Simplify Digital Annotations. Writing with a finger on a touch screen sounds intuitive, ......
Read more >To Define Flat-to-screen Annotation Orientation - PTC Support
About Home and Topic Pages · To Use the F1 Key for Context-Sensitive Help. What's New Creo 5.0. What's New: Creo Parametric 5.0.0.0....
Read more >Annotation tab (Solid Edge Options dialog box) - soliddna.com
In part and sheet metal models, you can use the Annotation tab to specify the ... annotation options for a variety of drawing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any information about this? Is there some workaround, or will it be implemented in near future?
There are two workarounds. One is inline classes (or tricking the serialization framework into thinking the class is inline - using a custom
SerialDescriptor
). The other is to use a custom serializer. If you give its descriptor as PrimitiveKind.String (there is a factory function for primitive descriptors, not even “internal”), then you can have the implementation just use encodeString, decodeString and do the “right” translation to get the objects.What isn’t really possible is to embed multi-attribute members into a parent (neither way really works), and that would require quite some changes on the compiler plugin side.