title: The method marshal(Object, Result) in the type Marshaller is not applicable for the arguments (T, File)
body: <p>i follow <a href="http://www.mkyong.com/java/jaxb-hello-world-example/" rel="nofollow">http://www.mkyong.com/java/jaxb-hello-world-example/</a>
  file or (Result)file got error java.io.File cannot be cast to javax.xml.transform.Result
  what is the correct writing?</p>
  
  <pre><code>File file = new File(path);
  JAXBContext jaxbContext = JAXBContext.newInstance(typeParameterClass.getClass());
  Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
  
  //output pretty printed
  jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
  
  jaxbMarshaller.marshal(boject, file);
  </code></pre>
  
  <p>Stacktrace</p>
  
  <pre><code>java.lang.ClassCastException: java.io.File cannot be cast to javax.xml.transform.Result
      at martin.XMLObj.ConvertObjectToXML(XMLObj.java:26)
      at martin.Helloworld.main(Helloworld.java:100)
  </code></pre>
  
  <p>Original code</p>
  
  <pre><code>Customer customer = new Customer();
  customer.setId(100);
  customer.setName("mkyong");
  customer.setAge(29);
  XMLObj&lt;Customer&gt; XMLtool = new XMLObj&lt;Customer&gt;(Customer.class);
  try {
      XMLtool.ConvertObjectToXML("c:\\file5.xml", customer);
  }
  catch(Exception ex)
  {
      ex.printStackTrace();
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>public class XMLObj&lt;T&gt; {
      final Class&lt;T&gt; typeParameterClass;
      public XMLObj(Class&lt;T&gt; typeParameterClass) {
          this.typeParameterClass = typeParameterClass;
      }
      public void ConvertObjectToXML(String path, T boject)
      {
          try {
              File file = new File(path);
              JAXBContext jaxbContext = JAXBContext.newInstance(typeParameterClass.getClass());
              Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
  
              //output pretty printed
              jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
  
              FileOutputStream fs = new FileOutputStream(file);
              jaxbMarshaller.marshal(boject, fs);
              fs.flush();
              fs.close();
  
              //jaxbMarshaller.marshal(boject, System.out);
          } catch (JAXBException e) {
              //e.printStackTrace();
              Logger.getInstance().process_message(e.getMessage());
          } catch (FileNotFoundException e) {
              // TODO Auto-generated catch block
              Logger.getInstance().process_message(e.getMessage());
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
      public T ConvertXMLToObject(String path)
      {
          //Convert XML to Object
          try {
              File file = new File(path);
              if(file.exists())
              {
                  JAXBContext jaxbContext;
                  jaxbContext = JAXBContext.newInstance(typeParameterClass.getClass());
                  Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
                  T bobj = (T) jaxbUnmarshaller.unmarshal(file);
                  System.out.println(bobj);
                  return bobj;
              }
              else
                  Logger.getInstance().process_message("File not exist in ConvertObjectToXML");
          } catch (JAXBException e) {
              // TODO Auto-generated catch block
              Logger.getInstance().process_message(e.getMessage());
          }
          return null;
      }
  }
  </code></pre>