title: Why doesn't JavaBeans serialize a property from type List<?>?
body: <p>I'm trying to do some simple XML serialization with JavaBeans, with an object having five getter/setter properties, and two getters. These two are from type List&lt;...> : </p>
  
  <pre><code>public List&lt;MasterDataQueryMDType&gt; getType() {
      if (type == null) {
          type = new ArrayList&lt;MasterDataQueryMDType&gt;();
      }
      return this.type;
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public List&lt;MasterDataQueryKey&gt; getKey() {
      if (key == null) {
          key = new ArrayList&lt;MasterDataQueryKey&gt;();
      }
      return this.key;
  }
  </code></pre>
  
  <p>I'm then using the XMLEncoder class (although here JAXB may be more appropriate, but I'm keeping it simple for now). The resulting XML has only the five getter/setter properties, the two properties of type List haven't been encoded. Is it because they are read only, or do I have to write a PersistenceDelegate for those kind of generic Lists ?</p>
  
  <hr>
  
  <p>Okay I've researched more, and the easiest way to solve this without going mad with writing its own PersistenceDelegate seems to be the creation of a wrapper class : </p>
  
  <pre><code>public class MasterDataQueryWrapper {
  private MasterDataQuery query;
  
  public MasterDataQuery getQuery(){
      return this.query;
  }
  public void setQuery(MasterDataQuery value){
      this.query = value;
  }
  public List&lt;MasterDataQueryMDType&gt; getType(){
      return query.getType();
  }
  public void setType(List&lt;MasterDataQueryMDType&gt; value){
      for (MasterDataQueryMDType t:value){
          this.query.getType().add(t);
      }
  }
  public List&lt;MasterDataQueryKey&gt; getKey(){
      return query.getKey();
  }
  public void setKey(List&lt;MasterDataQueryKey&gt; value){
      for (MasterDataQueryKey k:value){
          this.query.getKey().add(k);
      }
  }
  }
  </code></pre>
  
  <p>That way, java Beans has no problems getting and setting the read-only properties. However if you have a more elegant solution, feel free to chime in...</p>