title: Scala-Gson Deserialization: Attempted to deserialize a java.lang.Class. Forgot to register a type adapter?
body: <p><code>Exception in thread &quot;main&quot; java.lang.UnsupportedOperationException: Attempted to deserialize a java.lang.Class. Forgot to register a type adapter?</code></p>
  <p>I get that error message as I am trying to use gson deserialization in scala. i am new to scala</p>
  <p>I have an abstract class</p>
  <pre><code>abstract class Pie() {
  //does something
  }
  </code></pre>
  <p>I also have another class</p>
  <pre><code>class Apple (val apple: someclass) extends makeApplePie {
  // does something
  }
  class Peach (val peach: someclass) extends makePeachPie{
  //does something
  }
  </code></pre>
  <p>the abstract class makeApplePie</p>
  <pre><code>abstract class makeApplePie extends Pie{
  //does something
  }
  abstract class makePeachPie extends Pie{
      //does something
      }
  
  def getTypeOfPieFromString (test:String): Class[_ &lt;: Pie]= {
      test match {
        case &quot;Apple&quot; =&gt; classOf[makeApplePie]
        case &quot;Peach&quot; =&gt; classOf[makePeachPie]
        case _=&gt; classOf[makeApplePie]
  }}
  </code></pre>
  <p>so I want receive some input from a yaml file and i am using gson.json to parse the input to scala</p>
  <p>I dont know what kind of fruit will be added by user so I am using <code>Class [_ &lt;: Pie]</code>
  The question is how will i register typeAdapter for a <code>Class[_ &lt;:Pie]</code></p>
  <pre><code>new GsonBuilder().
      registerTypeAdapter(
      class[_ &lt;:Pie],
      new JsonDeserializer[_ &lt;:Pie] {
        override def deserialize(jsonElement: JsonElement, type: Type, context:JsonDeserializationContext): Class [_ &lt;: Pie] = {
             val name = jsonElement.getAsString
             //some function that gets class makeApplePie or makePeachPie
        getTypeOfPieFromString(name)
  
      }
  
  }
  )
  </code></pre>
  <p>this is where parsing is done</p>
  <pre><code>case class howManyPie (pieType : [_ &lt;:Pie])
  case class PieInput(InputPieType: java.util.HashMap[String, howManyPie ])
  
  // some parsing is done
  
   val bakePie = new startPie(
  //takes in a list in case user wants to bake multiple pies 
        pies = JavaConverters.iterableAsScalaIterable(pieInput.inputPieType.values()).toList)
  </code></pre>
  <p>Can anybody help?</p>