XStream
  1. XStream
  2. XSTR-195

Problems when deserializing array (like XSTR-185)

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1.1
    • Component/s: None
    • Labels:
      None
    • JDK version and platform:
      Sun 1.4.2._06 on Windows

      Description

      I hate to file what may be a duplicate bug (to XSTR-185), but unfortunately this bug tracking system does not allow me to re-open closed issues.

      Below is an example of the problem that persists with deserializing arrays. In other code, I still get ClassNotFound exception. However, in the code below, which is very simple, it just doesn't work and reports a different exception.

      Try:
      1. Running Foo with the command line "to" to generate and persist XML. Then, run Foo with no args to reveal the bug.

      import java.io.BufferedReader;
      import java.io.FileReader;
      import java.io.FileWriter;
      import java.io.PrintWriter;

      import com.thoughtworks.xstream.XStream;

      public class Foo
      {
      private int x = 100;

      public void printX()

      { System.out.println(x); }

      public static void toXML() throws Exception
      {
      XStream xstream = new XStream();
      Foo[] foos = new Foo[100];
      for (int i=0; i<foos.length; i++)

      { foos[i] = new Foo(); }

      String theXml = xstream.toXML(foos);
      PrintWriter pw = new PrintWriter(new FileWriter("tmp.dat"));
      pw.println(theXml);
      pw.flush();
      pw.close();
      }

      public static void fromXML() throws Exception
      {
      XStream xstream = new XStream();
      BufferedReader reader = new BufferedReader(new FileReader("tmp.dat"));
      String theXml = "";
      while (reader.ready())

      { theXml += reader.readLine(); }

      Foo[] f = (Foo[])xstream.fromXML(theXml);
      for (int i=0; i<f.length; i++)

      { f[i].printX(); }

      }

      public static void main(String[] args) throws Exception
      {
      if (args.length>0 && args[0].equals("to"))

      { toXML(); }

      else

      { fromXML(); }

      }
      }

      1. Foo.java
        1 kB
        Roger Thornhill

        People

        • Assignee:
          Unassigned
          Reporter:
          Roger Thornhill
        • Votes:
          0 Vote for this issue
          Watchers:
          1 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: