title: can't Deserialize a list of different types of children objects
body: <p>I have a json packet consisting of a dacket header(under PACKET_HEADER) + a number of different types of messages(under DATA). These messages have a same parent class:</p>
  
  <pre><code>//my packet class
  public class Packet {
      public PacketHeader PACKET_HEADER;
      public Message[] DATA;
  }
  
  //my parent message class:
  public class Message {
  
      public enum MessageType {
          WHOAREYOU,
          TimeData,
          Ready,
          LocationData
      }
  
      public MessageType getMessageType() {
          return MESSAGE_TYPE;
      }
  
      public void setMessageType(MessageType MessageType) {
          this.MESSAGE_TYPE = MessageType;
      }
  
      private MessageType MESSAGE_TYPE;
      //declaring public for simplicity
      public String SENDER;
      public String SENDER_TYPE;
  
  }
  
  //sample child class:
  public class TimeMessage extends Message {
  
      private int tick;
      public int getTick()
      {
          return tick;
      }
  </code></pre>
  
  <p>and I deserialize input like this:</p>
  
  <pre><code> @Override
      public Handler create(Connector connector, Object packet, int clientID) {
          Gson gson = new Gson();
          Packet pack = gson.fromJson(packet.toString(), Packet.class);
          System.out.println("Number of messages : " + pack.PACKET_HEADER.NOF_MESSAGES );//ok
          for(Message msg : pack.DATA)
          {
              switch (msg.getMessageType()) {
                  //enters the switch successfully
                  case TimeData: {               
                      System.out.println("Sender:  " + msg.SENDER  + "  Sender_type: " + msg.SENDER_TYPE);//ok
                      TimeMessage time_msg = (TimeMessage) msg;//NOT ok, generates exception!!!!
                      //...
                      return new TimeHandler(time_msg, connector, clientID);
                  }
                  default:                    
                      System.out.println("Switch " + msg.getMessageType() + " is invalid");
                      return null;
              }
          }
         return null; 
  
      }
  </code></pre>
  
  <p>Do you have any idea why I cant cast to a child class? how do i solve it. Thank a lot in advance.</p>