public <T>T fromXML(final HierarchicalStreamDriver driver,final Reader xml,final TypePermission... permissions) throws IOException, ClassNotFoundException {
  final XStream outer=new XStream(driver);
  for (  final TypePermission permission : permissions) {
    outer.addPermission(permission);
  }
  final HierarchicalStreamReader reader=driver.createReader(xml);
  final ObjectInputStream configIn=outer.createObjectInputStream(reader);
  try {
    final XStream configured=(XStream)configIn.readObject();
    final ObjectInputStream in=configured.createObjectInputStream(reader);
    try {
      @SuppressWarnings("unchecked") final T t=(T)in.readObject();
      return t;
    }
  finally {
      in.close();
    }
  }
  finally {
    configIn.close();
  }
}

public < T > T fromXML ( final HierarchicalStreamDriver driver , final Reader xml , final TypePermission ... permissions ) throws IOException , ClassNotFoundException { final XStream outer = new XStream ( driver ) ; for ( final TypePermission permission : permissions ) { outer . addPermission ( permission ) ; } final HierarchicalStreamReader reader = driver . createReader ( xml ) ; final ObjectInputStream configIn = outer . createObjectInputStream ( reader ) ; try { final XStream configured = ( XStream ) configIn . readObject ( ) ; final ObjectInputStream in = configured . createObjectInputStream ( reader ) ; try { @ SuppressWarnings ( "unchecked" ) final T t = ( T ) in . readObject ( ) ; return t ; } finally { in . close ( ) ; } } finally { configIn . close ( ) ; } }
deserialize a self - contained xstream with object from an xml reader .
