title: Serializing, deserializing arraylist<T>
body: <p>I'm trying to send serialized data using <code>gson</code> through sockets. The problem is that when I try to <code>deserialize</code> it gives me the following error</p>
  
  <pre><code>com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 47
  </code></pre>
  
  <p><code>ClientSocket</code> where I serialize:</p>
  
  <pre><code>public static void client(String ip, int port) throws IOException {
    try {
      ArrayList&lt;Sensor&gt; updatedSensorList = createSensor.getInstance().getSensorList();
       Gson gson = new Gson();
         Socket clientSocket = new Socket(ip, port);
          Type collectionType = new TypeToken&lt;ArrayList&lt;Sensor&gt;&gt;() {
              }.getType();
  
        DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
        String message = gson.toJson(updatedSensorList,collectionType);
         outToServer.writeBytes(message);
          clientSocket.close();
          } catch (IOException e) {
              System.out.println("Could not listen on port " + port);
          }
      }
  </code></pre>
  
  <p>The ServerSocket side where I try to deserialize</p>
  
  <pre><code>public class server extends Thread {
  
          private BufferedReader inFromClient;
          private Socket connectionSocket;
          ArrayList&lt;gateway.Sensor&gt; sensorList;
          int position, nextPort;
  
          public receivedMessages(Socket socket) {
              connectionSocket = socket;
  
          }
  
          @Override
          public void run() {
              try {
               InputStreamReader inFromClient = new InputStreamReader(connectionSocket.getInputStream());
               Type collectionType = new TypeToken&lt;ArrayList&lt;Sensor&gt;&gt;(){}.getType();
                  ArrayList&lt;Sensor&gt; sensorList = new Gson().fromJson(inFromClient, collectionType);        
              ////othercode 
         }
      }
  </code></pre>