title: Gson covert to and from only part of Json to kotlin
body: <p>I have an input json payload:</p>
  <pre><code>{
    &quot;header&quot;: null,
    &quot;body&quot;: {
      &quot;a&quot;: &quot;1,2,3,4,5&quot;,
      &quot;c&quot;: &quot;d&quot;,
      &quot;id&quot;: 23.5,
      &quot;number&quot;: 123
    }
  }
  </code></pre>
  <p>and my program needs to convert it to the following output payload:</p>
  <pre><code>{
    &quot;header&quot;: null,
    &quot;body&quot;: {
      &quot;a&quot;: [{&quot;a&quot;:&quot;1&quot;},{&quot;a&quot;:&quot;2&quot;},{&quot;a&quot;:&quot;3&quot;},{&quot;a&quot;:&quot;4&quot;},{&quot;a&quot;:&quot;5&quot;},],
      &quot;c&quot;: &quot;d&quot;,
      &quot;id&quot;: 23.5,
      &quot;id2&quot;: 23.5,
      &quot;number&quot;: 123
    }
  }
  </code></pre>
  <p>Header is always null in both input and output. I have created a class for input and output body:</p>
  <pre><code>data class InBody (
      val a: String,
      val c: String,
      val id: Double,
      val number: Long
  )
  data class OutBody (
      val a: List&lt;AIndividual&gt;,
      val c: String,
      val id: Double,
      val id2: Double,
      val number: Long
  )
  data class AIndividual(val a: String)
  
  </code></pre>
  <p>As you can see the transformation between both input required is minimal.</p>
  <ol>
  <li>Need to split <code>a</code> into a list of objects</li>
  <li>need to duplicate the <code>id</code> field to <code>id2</code> in output</li>
  </ol>
  <p>I am thinking to use Gson to convert the json to input model class to the output model class then output json.. Is there an easier way to do this instead??</p>
  <p>Also if I go according to this solution, how to use Gson to only read the <code>body</code> element of the <code>json</code> into the <code>InBody</code> class (and ignore header) and same when convert <code>OutBody</code> class to <code>json</code>??</p>
  <p>If Gson is not a suitable library for this and any other approach is better, please let me know..</p>