title: Adding static and instance methods to List in Kotlin
body: <p>I'm trying to add <a href="https://github.com/quicktype/quicktype/pull/838/files" rel="nofollow noreferrer">Kotlin support</a> to quicktype so that Kotlin developers can easy generate types and marshaling code in Kotlin from JSON.</p>
  
  <p>For any given JSON sample, I want to generate a type <code>T</code> with a <code>T.fromJson</code> static method and a <code>T.toJson</code> instance method, but I am stuck when the top-level type is not an object. For example, given the JSON</p>
  
  <pre><code>[
    { "name": "David" }
  ]
  </code></pre>
  
  <p><code>quicktype sample.json -t People -l kotlin</code> produces:</p>
  
  <pre><code>// To parse the JSON, add this file to your project and do:
  //
  //   val people = People.fromJson(jsonString)
  
  import com.beust.klaxon.*
  
  private val klaxon =
      Klaxon()
  
  typealias People = List&lt;Person&gt;
  
  data class Person (
      val name: String
  ) {
      public fun toJson() = klaxon.toJsonString(this as Any)
  
      companion object {
          public fun fromJson(json: String) = klaxon.parse&lt;Person&gt;(json)
      }
  }
  </code></pre>
  
  <p>What I need to do now is figure out how to add the <code>fromJson</code> and <code>toJson</code> methods to the <code>People</code> type. Here was my first attempt:</p>
  
  <pre><code>open class People {
      public fun toJson() = klaxon.toJsonString(this as Any)
  
      companion object {
          public fun fromJson(json: String) = klaxon.parseArray&lt;Person&gt;(json)
      }
  }
  </code></pre>
  
  <p>But I could not write <code>open class People</code> so I removed the alias:</p>
  
  <pre><code>open class List&lt;Person&gt; {
      public fun toJson() = klaxon.toJsonString(this as Any)
  
      companion object {
          public fun fromJson(json: String) = klaxon.parseArray&lt;Person&gt;(json)
      }
  }
  </code></pre>
  
  <p>But now <code>people.toJson()</code> does not compile because the compiler cannot find the method.</p>
  
  <p>Can I accomplish the semantics I want in Kotlin?</p>