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.

`@SerialComment` annotation

See original GitHub issue

What is your use-case and why do you need this feature?

@SerialComment annotation will be useful for automatically generated configuration files. Some serialization libraries already implemented that feature including:

And it’s possible to add comment support in other libraries like:

The problem is that they are using/will use different @Comment annotations

Describe the solution you’d like

  • Add @SerialComment annotation
  • SerialDescriptor.getElementComment(index: Int): String function to get property comment SerialFormat.supportsComments property to check if SerialFormat supports comment serialization (false by default)

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sgammoncommented, Oct 14, 2022

i wonder, though, if it is possible to do make this happen without a dedicated annotation. does the compiler plugin support comments? could it just take the native Kotlin comment from the property?

1reaction
vnermolaevcommented, Jul 8, 2022

@slava110, I guess you can already achieve the goal as follows

@SerialInfo
@Target(AnnotationTarget.PROPERTY)
annotation class SerialComment(val comment: String)

fun SerialDescriptor.getElementComment(index: Int): String =
  getElementAnnotations(index)
      .filterIsInstance<SerialComment>()
      .singleOrNull()
      ?.comment
      ?: ""

@Serializable
data class Container(
    @SerialComment("Property is used for demonstration")
    val i: Int
)

fun main(args: Array<String>) {
    println(Container.serializer().descriptor.getElementComment(0))
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Annotations - serializer Documentation (master)
This annotation can be defined on a property or a class to indicate that the property or class should not be serialized/unserialized.
Read more >
Control liquibase migration scripts on different environments.
`id` SERIAL COMMENT 'Auto-generated monotonically increasing id of the table.', ... import org.springframework.context.annotation.Bean;
Read more >
Guide to the @Serial Annotation in Java 14 | Baeldung
Learn how to apply the @Serial annotation in Java 14 to assist with compile-time checks on serializable properties of a class.
Read more >
cham_avr_user_manual_v1-890.pdf - Mouser Electronics
Figure 1.1 shows an image of the Chameleon AVR 8-bit annotated. ... of the programs that use serial comment out the include file...
Read more >
Reading, Society and Politics in Early Modern England
... voices of the era, the comment serial. Comment serials – regular printed ... it explores the habits of compilation and annotation that...
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