Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat libs can I use to bind POJOs to external files for TDD without much overhead?
    text
    copied!<p>I need a way to bind POJO objects to an external entity, that could be XML, YAML, structured text or anything easy to write and maintain in order to create Mock data for unit testing and TDD. Below are some libraries I tried, but the main problems with them were that I am stuck (for at least more 3 months) to Java 1.4. I'd like any insights on what I could use instead, with as low overhead and upfront setup (like using Schemas or DTDs, for instance) as possible and without complex XML. Here are the libraries I really like (but that apparently doesn't work with 1.4 or doesn't support constructors - you gotta have setters):</p> <p><b>RE-JAXB (or Really Easy Java XML Bindings)</b></p> <p><a href="http://jvalentino.blogspot.com/2008/07/in-response-to-easiest-java-xml-binding.html" rel="nofollow noreferrer"><a href="http://jvalentino.blogspot.com/2008/07/in-response-to-easiest-java-xml-binding.html" rel="nofollow noreferrer">http://jvalentino.blogspot.com/2008/07/in-response-to-easiest-java-xml-binding.html</a></a> <a href="http://sourceforge.net/projects/rejaxb/" rel="nofollow noreferrer"> <a href="http://sourceforge.net/projects/rejaxb/" rel="nofollow noreferrer">http://sourceforge.net/projects/rejaxb/</a></a></p> <p>Seamlessy binds this:</p> <pre><code>&lt;item&gt; &lt;title&gt;Astronauts' Dirty Laundry&lt;/title&gt; &lt;link&gt;http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp&lt;/link&gt; &lt;description&gt;Compared to earlier spacecraft, the International Space Station has many luxuries, but laundry facilities are not one of them. Instead, astronauts have other options.&lt;/description&gt; &lt;pubDate&gt;Tue, 20 May 2003 08:56:02 GMT&lt;/pubDate&gt; &lt;guid&gt;http://liftoff.msfc.nasa.gov/2003/05/20.html#item570&lt;/guid&gt; &lt;/item&gt; </code></pre> <p>To this:</p> <pre><code>@ClassXmlNodeName("item") public class Item { private String title; private String link; private String description; private String pubDate; private String guid; //getters and settings go here... } </code></pre> <p>Using:</p> <pre><code>Rss rss = new Rss(); XmlBinderFactory.newInstance().bind(rss, new File("Rss2Test.xml")); </code></pre> <p>Problem: It relies on annotations, so no good for Java 1.4</p> <p><b>jYaml</b> <a href="http://jyaml.sourceforge.net/" rel="nofollow noreferrer"><a href="http://jyaml.sourceforge.net/" rel="nofollow noreferrer">http://jyaml.sourceforge.net/</a></a></p> <p>Seamlessly binds this:</p> <pre><code>--- !user name: Felipe Coury password: felipe modules: - !module id: 1 name: Main Menu admin: !user name: Admin password: password </code></pre> <p>To this:</p> <pre><code>public class User { private String name; private String password; private List modules; } public class Module { private int id; private String name; private User admin; } </code></pre> <p>Using:</p> <pre><code>YamlReader reader = new YamlReader(new FileReader("example.yaml")); reader.getConfig().setClassTag("user", User.class); reader.getConfig().setClassTag("module", Module.class); User user = (User) reader.read(User.class); </code></pre> <p>Problem: It won't work with constructors (so no good for immutable objects). I'd have to either change my objects or write custom code por handling the YAML parsing.</p> <p>Remember that I would like to avoid - as much as I can - writing data descriptors, I'd like something that "just works".</p> <p>Do you have any suggestions?</p>
 

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