title: Java JSON deserialize inheritance class
body: <p>I am using Gson to deserialize a class which is inherited from an abstract class. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>public abstract class Mammal {
      private String name;
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getName(){
          return name;
      }
  }
  
  public class Dog extends Mammal {
      public void bark(){
  
      }
  }
  
  public class Cat extends Mammal{
  
      public void mew(){
  
      }
  }
  
  public class Main {
      public static void main(String[] args) {
          Gson gson = new Gson();
          Mammal dog = new Dog();
          String toGson = gson.toJson(dog);
          Mammal aDog = gson.fromJson(toGson, Mammal.class);
      }
  }
  </code></pre>
  
  <p>An exception is thrown when I run it, can someone tell me how to fix this?</p>