-
Notifications
You must be signed in to change notification settings - Fork 637
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
@SerialComment
annotation
#1970
Comments
In other words, is it correct to summarise that you see a use case for having generalized support for including comments into serialized documents. Before we go thinking through what it really means there is one point about the Another part is what shape would these comments take. It appears that you want to have the annotation be specified on types, not use sites/fields. However the question is how a format would interpret this. If it is a top level comment, would this be included as part of the "document" comments? If not, will this be written out any time the type is written? (only the first time instead)? These choices need to be clear for a general purpose library. Perhaps making it easier to extend the format for this purpose may make things easier. Besides these questions I'm not sure what the exact use case is. Is it only to have a top level comment on a document? In such case that is something best directly done directly on the format (perhaps when configuring it) although some sort of common configuration could be beneficial. |
Yep, maybe there's no point in
Actually I wanted to have the annotation be specified on properties, not types, yeah (Updated my original comment)
Commented properties are useful for any type of automatically generated configuration files. Developers will be able to tell users what should be put in certain JSON properties for example |
@slava110 So the use case is really configuration files. I can see that one. It doesn't really suffer from the repetition issue much and I certainly recognize the value of explanations/instructions in configuration files. |
BTW, even if protobuf doesn't support comments in messages, it could be useful for schema generation to have comments there. /**
* @property used for ...
*/
data class SomeData(
@SerialComment("property used for ...")
val property: String
) |
@pdvrieze I think maintaining set of type/field information that has already written will add unnecessary complexity and will create more questions. It's an idea for completely different issue |
@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))
}
|
@vnermolaev , Please read my first comment in this issue. Thanks |
@whyoleg > BTW, even if protobuf doesn't support comments in messages do you mean at runtime? protobuf does support comments in messages. actually this is my use case for finding this issue. @pdvrieze perhaps my use case helps too. i want to preserve comments from Kotlin i will try your workaround @vnermolaev because i'm extending the protobuf generator, so this may work for me. |
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? |
Is this issue being worked on at all? I'd really love to see comment support in kotlinx.serialization |
@solonovamax No, it is not in our current plans. |
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
annotationsDescribe the solution you'd like
@SerialComment
annotationSerialDescriptor.getElementComment(index: Int): String
function to get property commentSerialFormat.supportsComments
property to check ifSerialFormat
supports comment serialization (false
by default)The text was updated successfully, but these errors were encountered: