title: What is the best way to mock DTOs in Java?
body: <p>When writing unit tests I need some objects with sample data. For example suppose I have an Order object. One needs to write code like this - </p>
  
  <pre><code>Order o = new Order();
  o.setId(3);
  o.setAmount(2830.9);
  
  List&lt;Item&gt; items = new ArrayList&lt;Item&gt;();
  Item i = new Item();
  i.setId(3);
  i.setCost(34);
  items.add(i);
  
  o.setItems(items);
  </code></pre>
  
  <p>It is a lot more frustrating and redundant than it looks here because a real object is likely to have lot more attributes and nested objects.</p>
  
  <p>And if one needs multiple orders ...</p>
  
  <p>What is the best way to create mock data objects for testing?</p>
  
  <p>Off the top of my head I'm thinking about deserializing my objects from Json. Is there a standard, efficient way to do this?</p>