yamlkt icon indicating copy to clipboard operation
yamlkt copied to clipboard

Serialize / Deserialize comments through `Commentable<Any>`

Open chachako opened this issue 4 years ago • 2 comments

I propose to add a new object instead of using an annotation to decode / encoding comments, so it can support comments for each element?

proposal:

// primitive:
data class CommentableInt(val comment: String, val value: Int)
data class CommentableBoolean(val comment: String, val value: Boolean)
data class CommentableFloat(val comment: String, val value: Float)
...
data class Commentable<T>(val comment: String, val value: T)

yml:

# people's rating
rank: 80
foods: # list declaration
  # need a pizza
  pizza: true
takeout: true

kotlin:

@Serializable
data class Test(
  val rank: CommentableInt,
  val foods: List<Commentable<String>>,
  val takeout: CommentableBoolean,
)

Also, it seems impossible to serialize comments as objects at present, or do I miss something?

chachako avatar Sep 29 '21 16:09 chachako

Looks good but this feature requires yamlkt to recognize (the positions of) comments (for now we just ignore all tokens after #).

Him188 avatar Sep 29 '21 16:09 Him188

Look forward to this! I haven not figured out the principle of this library yet, otherwise I am very interested in this PR.

chachako avatar Sep 30 '21 03:09 chachako