views:

8

answers:

0

So I'm writing a program which has a large number of classes that need to be written out to XML, and then read in from XML later. I found that Betwixt turns the Classes I have into XML, writes it to file, and then reads back in the same stuff to instantiate a class. Awesome. Just what I wanted.

I happen to have a class which is Supposed to read/Write to/from file. It has a Name, a Description, and then a list of tags (Strings) stored in a vector. Output works wonderfully, it makes a very pretty XML file which I can read no problem and contains everything I could ever possibly want.

However, when I try to read it back in, none of my Strings come back, instead returning me a Null Pointer where the vector should be. This is... extremely problematic, and the Betwixt documentation has been little help thus far (What little of it I can find, I must be missing something)

Below is the code I'm using, which, as far as I can find for every tutorial, should work.

    public class TerrainProperties{
 private String name;
 private String description;
 private Vector<String> tags;

 //setters
 public void setName(String nm){name=nm;}
 public void setDescription(String desc){description=desc;}
 public void setTags(Vector<String> tgs){tags=tgs;}

 //getters
 public String getName(){return name;}
 public String getDescription(){return description;}
 public Vector<String> getTags(){return tags;}


 void readFromFile(String filename) {
  TerrainProperties temp = new TerrainProperties();
  FileReader xmlreader;
  BeanReader classreader;
  classreader = new BeanReader();
            //Set Properties for the reader
 classreader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
  classreader.getBindingConfiguration().setMapIDs(false);

   xmlreader= new FileReader(filename);
   classreader.registerBeanClass("TerrainProperty", TerrainProperties.class);

            //Actually have it read in from the file.
   temp = (TerrainProperties)classreader.parse(xmlreader);

            //Intialized appropriatly
  name=temp.getName();
  description=temp.getDescription();

            //NULL!!! RAWRRR!!!!
  tags=temp.getTags();
 }



    //This all works.
 void writeToFile(String filename){
  FileWriter xmlwriter;

   xmlwriter = new FileWriter(filename);
   classwriter = new BeanWriter(xmlwriter); 
         classwriter.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
         classwriter.getBindingConfiguration().setMapIDs(false);
         classwriter.enablePrettyPrint();
   classwriter.write("TerrainProperty",this);
   xmlwriter.flush();
   xmlwriter.close();
 }


}