title: Dynamic CDATA in JAXB using MOXy
body: <p>I am using <a href="http://www.eclipse.org/eclipselink/moxy.php" rel="nofollow"><strong>EclipseLink JAXB (MOXy)</strong></a>. I have an issue where a property of a java class can be CDATA or not dynamically. For example, </p>
  
  <pre class="lang-java prettyprint-override"><code>class Embed{  
  //@XmlValue only  
  //OR @XmlValue @CDATA  
  private String value; //THIS CAN BE CDATA OR NOT  
  }
  </code></pre>
  
  <p>I have tried solving the issue using inheritance where one subclass has the property as just a value and another one as CDATA. The problem i have with this solution is that the generated Xml has xsi:type and xmlns:xsi information which i don't want since i am upgrading legacy code and i need the resulted xml exactly as the legacy one.</p>
  
  <p>The solution i have tried:</p>
  
  <pre class="lang-java prettyprint-override"><code>@XmlAccessorType(XmlAccessType.FIELD)  
  @XmlType(name = "itemType", namespace = "", propOrder = {"embed"}  
  public class Item{  
   List`&lt;Embed&gt;` embed;  
   //getter and setters  
  }
  
  @XmlAccessorType(XmlAccessType.NONE)  
  @XmlSeeAlso(EmbedDefault.class, EmbedAsCdata.class)  
  public abstract class Embed{
  
  }
  
  @XmlAccessorType(XmlAccessType.FIELD)    
  @XmlType( propOrder = {"value"})  
  public class EmbedDefault extends Embed{
  
  @XmlValue
  protected String value;
   //getters and setters  
  }
  
  @XmlAccessorType(XmlAccessType.FIELD)  
  @XmlType(propOrder = {"value"})  
  public class EmbedAsCdata extends Embed {  
  
  @XmlValue
  @XmlCDATA
  protected String value;
  //getters and setters  
  }
  </code></pre>
  
  <p>Is there such another easier approach?</p>