question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@Flat option annotation

See original GitHub issue

I 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 like IllegalArgumentException
  • Collections in this case, I think, must be interpreted as associated map: with keys numbers and values - values if list

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:48
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
Coneyscommented, Dec 28, 2020

Any information about this? Is there some workaround, or will it be implemented in near future?

1reaction
pdvriezecommented, May 18, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found