9 Replies Latest reply on Mar 1, 2011 2:37 AM by 843437

    Error in deserialisation....

      I am trying to serialize the object of my class locally as well as over the network to the server. When I try to retrieve the object by deserialization locally I get back the state of the object, but when I try to deserialize it over the network, one of the fields is null. The field which is turning out null is
        private List<Instruction> negativeExamples = new LinkedList<Instruction>();
      I have marked the
       class Instruction 
      as implementing the serializable interface. The portion of code which saves the object over the network is:
           public void storeObject(String key, Object object) throws IOException {
                String location = locationURL+"/Servlet/stores?cmd=storeObj&file="+key;
                URL servlet = new URL(location);
                URLConnection servletConnection = servlet.openConnection();
                servletConnection.setRequestProperty("Content-Type", "application/octet-stream");
                //OutputStream output = servletConnection.getOutputStream();
                ObjectOutputStream output = new ObjectOutputStream(servletConnection.getOutputStream());
                InputStream input = servletConnection.getInputStream();
                String dataString = "";
                int data = input.read();
                while(data != -1)
                     dataString = dataString + (char)data;
                     data = input.read();
                trace.out("miss", "Inside storeObject");
                trace.out("miss", "DataString:    " + dataString);
      For further debugging I tried to get back the state of the object that I wrote to the server immediately after I have written the object and even the field for that
      object is turning out to be null.

      The code which is used to get back the object from the server is:
           public Object retrieveObject(String key) throws IOException {
                String location = locationURL+"/Servlet/stores?cmd=retrieveObj&file="+key;
                URL servlet = new URL(location);
                URLConnection servletConnection = servlet.openConnection();
                ObjectInputStream inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());
                Object object = null;
                try {
                     object = inputFromServlet.readObject();
                } catch (ClassNotFoundException e) {
                // Close the stream
                return object;
      What can be the reason for it? I know that the thing works fine when I save it to a file locally and then retrieve it back but this thing over the network is turning out to be well something mysterious. Any help or suggestions would be appreciated.