无法将Java对象保存到XML文件

时间:2015-12-01 19:35:33

标签: java xml

我想将我的Object Mall保存为XML,但是当我打开XML文件时似乎没有保存。是因为Mall类中有太多对象要保存,因此无法保存?

以下是我的代码:

Mall Class

   public class Mall implements ActionExecute,Serializable {

    private static Mall singleton = null;
    private  ArrayList<Store> storeList = new ArrayList ();
    private  ArrayList<Customer> customerList = new ArrayList ();
    public static Mall instance()
    {
        if(singleton == null)
        {
            singleton = new Mall();

        }
       return singleton;
    }

  public void createStore(String factory,String storeType,String storeName)
      {

          AbstractFactory Factory  = FactoryProducer.getFactory(factory);

          if(factory.equals("store"))
          {
          Store newstore = Factory.getStore(storeType,storeName);
          storeList.add(newstore);
          }
             }

SaveFile Class

public class saveFile {
 public static void write(Mall f) throws Exception{
     try (XMLEncoder encoder = new XMLEncoder(
                                  new BufferedOutputStream(
                                    new FileOutputStream("designpattern.xml")))) {
         encoder.writeObject(f);
     }
}
}

XML文件结果

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.7.0_25" class="java.beans.XMLDecoder">
<object class="designpattern.Mall"/>
</java>

0 个答案:

没有答案