Does this look good? ```@Serializable data class C...
# serialization
s
Does this look good?
Copy code
@Serializable
data class Commit(
    val hash: String = "%h",
    val author: String = "%an",
    val timestamp: String = "%at",
    val subject: String = "%f"
)

fun getCommits(repoFolder: File, amount: Int = Integer.MAX_VALUE): List<Commit> {
    val baseJson = jsonWithDefaults.encodeToString(Commit()).replace("\"", "\\\"") + "__split__"
    val log = exec("git log -$amount --format=\"$baseJson\"", repoFolder)
    return log
        .split("__split__")
        .filter { it.isNotEmpty() }
        .map { Json.decodeFromString<Commit>(it) }
}
Ive seen other people serialize git log using the --format command, by manually writing json which was really ugly. I thought this could be neater with kotlin serialization
a
That looks like a clever idea to me! I'd be a bit wary about having the default args - just in case I accidentally didn't correctly pass the correct data in and end up with I'd probably split up the implementation into a template and data class and create a CommitSpec interface to make sure each one is aligned. Now there's no chance about forgetting to set a property in the Commit class.
Copy code
interface CommitSpec {
  val hash: String
  // ...
}

@Serializable
data class Commit(
  override hash: String,
  // ...
) : CommitSpec

@Serializable
class CommitTemplate : CommitSpec {
  @EncodeDefault
  override hash: String = "%h"
  // ...
}
However, it would be much more verbose so if what you've got works then I'd stick with it :)