I can't cast my object after sending it with netty
<p>When I read the response in the server, I get the right object but when I try to cast it to Packet, I got this exception :</p>

<pre><code>java.lang.ClassCastException: java.lang.String cannot be cast to server.Packet
    at server.JCoincheServerHandler.channelRead(JCoincheServerHandler.java:21)
</code></pre>

<p>This is my packet class :</p>

<pre><code>public class Packet implements Serializable
{
    public int code;
    int intData;
    String data;
    String user;
}
</code></pre>

<p>This is how I send it in my client:
The sending is successful, "send failed" is never printed</p>

<pre><code>    public void sendMessage(Object object)
    {
        ChannelFuture cf = _chan.write(object);
        _chan.flush();
        if (!cf.isSuccess()) {
            System.out.println("Send failed: " + cf.cause());
        }
}
</code></pre>

<p>This is how I read it in my server:</p>

<pre><code>@Override
   public void channelRead(ChannelHandlerContext ctx, Object msg) {
       Packet packet = (Packet) msg;
       System.out.println(packet.data);
       System.out.println("Message received");
   }
</code></pre>

<p>What did I do wrong ?</p>

<p>EDIT:</p>

<pre><code>p.addLast(
          new ObjectEncoder(),
          new ObjectDecoder(ClassResolvers.cacheDisabled(null)),
          handler);
</code></pre>