Note that there are some explanatory texts on larger screens.

plurals
  1. POXML to Object conversion process other than xstream
    primarykey
    data
    text
    <p>I was using xstream api as shown below but now please advise can I achieve the same thing of xml to java object conversion process with API other than xstream in java itself like JAXB. Please adivse if it is possible then how can I convert this other than using xstream..</p> <p>Suppose we have a requirement to load configuration from xml file:</p> <pre><code>01 &lt;config&gt; 02 &lt;inputFile&gt;/Users/tomek/work/mystuff/input.csv&lt;/inputFile&gt; 03 &lt;truststoreFile&gt;/Users/tomek/work/mystuff/truststore.ts&lt;/truststoreFile&gt; 04 &lt;keystoreFile&gt;/Users/tomek/work/mystuff/CN-user.jks&lt;/keystoreFile&gt; 05 06 &lt;!-- ssl stores passwords--&gt; 07 &lt;truststorePassword&gt;password&lt;/truststorePassword&gt; 08 &lt;keystorePassword&gt;password&lt;/keystorePassword&gt; 09 10 &lt;!-- user credentials --&gt; 11 &lt;user&gt;user&lt;/user&gt; 12 &lt;password&gt;secret&lt;/password&gt; 13 &lt;/config&gt; </code></pre> <p>And we want to load it into Configuration object:</p> <pre><code>01 public class Configuration { 02 03 private String inputFile; 04 private String user; 05 private String password; 06 07 private String truststoreFile; 08 private String keystoreFile; 09 private String keystorePassword; 10 private String truststorePassword; 11 12 // getters, setters, etc. 13 } </code></pre> <p>So basically what we have to do is:</p> <pre><code>1 FileReader fileReader = new FileReader("config.xml"); // load our xml file 2 XStream xstream = new XStream(); // init XStream 3 // define root alias so XStream knows which element and which class are equivalent 4 xstream.alias("config", Configuration.class); 5 Configuration loadedConfig = (Configuration) xstream.fromXML(fileReader); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload