| <!-- |
| /*************************************************************************************************************************** |
| * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations under the License. |
| ***************************************************************************************************************************/ |
| --> |
| |
| @Xml(format) Annotation |
| |
| <p> |
| The {@link oaj.xml.annotation.Xml#format() @Xml(format)} annotation can be used to tweak |
| the XML format of a POJO. |
| The value is set to an enum value of type {@link oaj.xml.annotation.XmlFormat}. |
| This annotation can be applied to both classes and bean properties. |
| </p> |
| <p> |
| The {@link oaj.xml.annotation.XmlFormat#ATTR} format can be applied to bean properties to |
| serialize them as XML attributes instead of elements. |
| Note that this only supports properties of simple types (e.g. strings, numbers, booleans). |
| </p> |
| |
| <h5 class='figure'>Example</h5> |
| <table class='styled w800'> |
| <tr> |
| <th>Data type</th> |
| <th>JSON example</th> |
| <th>Without annotation</th> |
| <th>With annotation</th> |
| </tr> |
| <tr> |
| <td class='code'> |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>ATTR</jsf>) |
| <jk>public</jk> String a; |
| } |
| </td> |
| <td class='code'> |
| { |
| a: <js>'foo'</js> |
| } |
| </td> |
| <td class='code'><xt> |
| <object> |
| <a><xv>foo</xv></a> |
| </object> |
| </xt></td> |
| <td class='code'><xt> |
| <object <xa>a</xa>=<xs>'foo'</xs>/> |
| </xt></td> |
| </tr> |
| </table> |
| <p> |
| The {@link oaj.xml.annotation.XmlFormat#ATTRS} format can be applied to bean classes to |
| force all bean properties to be serialized as XML attributes instead of child elements. |
| </p> |
| |
| <h5 class='figure'>Example</h5> |
| <table class='styled w800'> |
| <tr> |
| <th>Data type</th> |
| <th>JSON example</th> |
| <th>Without annotation</th> |
| <th>With annotation</th> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>ATTRS</jsf>) |
| <jk>class</jk> MyBean { |
| <jk>public</jk> String a; |
| <jk>public int</jk> b; |
| } |
| </td> |
| <td class='code'> |
| { |
| a: <js>'foo'</js>, |
| b: 123 |
| } |
| </td> |
| <td class='code'><xt> |
| <object> |
| <a><xv>foo</xv></a> |
| <b><xv>123</xv></b> |
| </object> |
| </xt></td> |
| <td class='code'><xt> |
| <object <xa>a</xa>=<xs>'foo'</xs> <xa>b</xa>=<xs>'123'</xs>/> |
| </xt></td> |
| </tr> |
| </table> |
| <p> |
| The {@link oaj.xml.annotation.XmlFormat#ELEMENT} format can be applied to bean properties |
| to override the {@link oaj.xml.annotation.XmlFormat#ATTRS} format applied on the bean |
| class. |
| </p> |
| |
| <h5 class='figure'>Example</h5> |
| <table class='styled w800'> |
| <tr> |
| <th>Data type</th> |
| <th>JSON example</th> |
| <th>Without annotation</th> |
| <th>With annotation</th> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>ATTRS</jsf>) |
| <jk>class</jk> MyBean { |
| <jk>public</jk> String a; |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>ELEMENT</jsf>) |
| <jk>public int</jk> b; |
| } |
| </td> |
| <td class='code'> |
| { |
| a: <js>'foo'</js>, |
| b: 123 |
| } |
| </td> |
| <td class='code'><xt> |
| <object> |
| <a><xv>foo</xv></a> |
| <b><xv>123</xv></b> |
| </object> |
| </xt></td> |
| <td class='code'><xt> |
| <object <xa>a</xa>=<xs>'foo'</xs></xs>> |
| <b><xv>123</xv></b> |
| </object> |
| </xt></td> |
| </tr> |
| </table> |
| <p> |
| The {@link oaj.xml.annotation.XmlFormat#ATTRS} format can be applied to a single bean |
| property of type <c>Map<String,Object></c> to denote arbitrary XML attribute values on the |
| element. |
| These can be mixed with other {@link oaj.xml.annotation.XmlFormat#ATTR} annotated |
| properties, but there must not be an overlap in bean property names and map keys. |
| </p> |
| |
| <h5 class='figure'>Example</h5> |
| <table class='styled w800'> |
| <tr> |
| <th>Data type</th> |
| <th>JSON example</th> |
| <th>Without annotation</th> |
| <th>With annotation</th> |
| </tr> |
| <tr> |
| <td class='code'> |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>ATTRS</jsf>) |
| <jk>public</jk> Map<String,Object> a; |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>ATTR</jsf>) |
| <jk>public int</jk> b; |
| } |
| </td> |
| <td class='code'> |
| { |
| <jok>a</jok>: { |
| <jok>k1</jok>: <jov>'foo'</jov>, |
| <jok>k2</jok>: <jov>123</jov>, |
| }, |
| <jok>b</jok>: <jov>456</jov> |
| } |
| </td> |
| <td class='code'><xt> |
| <object> |
| <a> |
| <k1><xv>foo</xv></k1> |
| <k2 <xa>_type</xa>=<xs>'number'</xs>><xv>123</xv></k2> |
| </a> |
| <b><xv>456</xv></b> |
| </object> |
| </xt></td> |
| <td class='code'><xt> |
| <object <xa>k1</xa>=<xs>'foo'</xs> <xa>k2</xa>=<xs>'123'</xs> <xa>b</xa>=<xs>'456'</xs>/> |
| </xt></td> |
| </tr> |
| </table> |
| <p> |
| The {@link oaj.xml.annotation.XmlFormat#COLLAPSED} format can be applied to bean properties |
| of type array/Collection. |
| This causes the child objects to be serialized directly inside the bean element. |
| This format must be used in conjunction with {@link oaj.xml.annotation.Xml#childName() @Xml(childName)} |
| to differentiate which collection the values came from if you plan on parsing the output back into beans. |
| Note that child names must not conflict with other property names. |
| </p> |
| <table class='styled w800'> |
| <tr> |
| <th>Data type</th> |
| <th>JSON example</th> |
| <th>Without annotation</th> |
| <th>With annotation</th> |
| </tr> |
| <tr> |
| <td class='code'> |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(childName=<js>"A"</js>,format=XmlFormat.<jsf>COLLAPSED</jsf>) |
| <jk>public</jk> String[] a; |
| <ja>@Xml</ja>(childName=<js>"B"</js>,format=XmlFormat.<jsf>COLLAPSED</jsf>) |
| <jk>public int</jk>[] b; |
| } |
| </td> |
| <td class='code'> |
| { |
| a: [<js>'foo'</js>,<js>'bar'</js>], |
| b: [123,456] |
| } |
| </td> |
| <td class='code'><xt> |
| <object> |
| <a> |
| <string><xv>foo</xv></string> |
| <string><xv>bar</xv></string> |
| </a> |
| <b> |
| <number><xv>123</xv></number> |
| <number><xv>456</xv></number> |
| </b> |
| </object> |
| </xt></td> |
| <td class='code'><xt> |
| <object> |
| <A><xv>foo</xv></A> |
| <A><xv>bar</xv></A> |
| <B><xv>123</xv></B> |
| <B><xv>456</xv></B> |
| </object> |
| </xt></td> |
| </tr> |
| </table> |
| <p> |
| The {@link oaj.xml.annotation.XmlFormat#ELEMENTS} format can be applied to a single bean |
| property of either a simple type or array/Collection. |
| It allows free-form child elements to be formed. |
| All other properties on the bean MUST be serialized as attributes. |
| </p> |
| <table class='styled w800'> |
| <tr> |
| <th>Data type</th> |
| <th>JSON example</th> |
| <th>With annotation</th> |
| </tr> |
| <tr> |
| <td class='code'> |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>ATTR</jsf>) |
| <jk>public</jk> String a; |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>ELEMENTS</jsf>) |
| <jk>public</jk> String b; |
| } |
| </td> |
| <td class='code'> |
| { |
| a: <js>'foo'</js>, |
| b: <js>'bar'</js> |
| } |
| </td> |
| <td class='code'><xt> |
| <object <xa>a</xa>=<xs>'foo'</xs>> |
| <string><xv>bar</xv></string> |
| </object> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>ATTR</jsf>) |
| <jk>public</jk> String a; |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>ELEMENTS</jsf>) |
| <jk>public</jk> Object[] b; |
| } |
| </td> |
| <td class='code'> |
| { |
| a: <js>'foo'</js>, |
| b: [ |
| <js>'bar'</js>, |
| <js>'baz'</js>, |
| 123, |
| <jk>true</jk>, |
| <jk>null</jk> |
| ] |
| } |
| </td> |
| <td class='code'><xt> |
| <object <xa>a</xa>=<xs>'foo'</xs>> |
| <string><xv>bar</xv></string> |
| <string><xv>baz</xv></string> |
| <number><xv>123</xv></number> |
| <boolean><xv>true</xv></boolean> |
| <null/> |
| </object> |
| </xt></td> |
| </tr> |
| </table> |
| <p> |
| The {@link oaj.xml.annotation.XmlFormat#MIXED} format is similar to |
| {@link oaj.xml.annotation.XmlFormat#ELEMENTS} except elements names on primitive types |
| (string/number/boolean/null) are stripped from the output. |
| This format particularly useful when combined with bean dictionaries to produce mixed content. |
| The bean dictionary isn't used during serialization, but it is needed during parsing to resolve bean |
| types. |
| </p> |
| <p> |
| The {@link oaj.xml.annotation.XmlFormat#MIXED_PWS} format identical to |
| {@link oaj.xml.annotation.XmlFormat#MIXED} except whitespace characters are preserved in |
| the output. |
| </p> |
| <table class='styled w800'> |
| <tr> |
| <th>Data type</th> |
| <th>JSON example</th> |
| <th>Without annotations</th> |
| <th>With annotations</th> |
| </tr> |
| <tr> |
| <td class='code'> |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>MIXED</jsf>) |
| <ja>@Beanp</ja>(dictionary={MyBeanX.<jk>class</jk>, MyBeanY.<jk>class</jk>}) |
| <jk>public</jk> Object[] a; |
| } |
| |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBeanX { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>ATTR</jsf>) |
| <jk>public</jk> String b; |
| } |
| |
| <ja>@Bean</ja>(typeName=<js>"Y"</js>) |
| <jk>class</jk> MyBeanY { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>ATTR</jsf>) |
| <jk>public</jk> String c; |
| } |
| </td> |
| <td class='code'> |
| { |
| a: [ |
| <js>'foo'</js>, |
| { _type:<js>'X'</js>, b:<js>'bar'</js> } |
| <js>'baz'</js>, |
| { _type:<js>'Y'</js>, b:<js>'qux'</js> }, |
| <js>'quux'</js> |
| ] |
| } |
| </td> |
| <td class='code'><xt> |
| <object> |
| <a> |
| <string><xv>foo</xv></string> |
| <object> |
| <b><xv>bar</xv></b> |
| </object> |
| <string><xv>baz</xv></string> |
| <object> |
| <b><xv>qux</xv></b> |
| </object> |
| <string><xv>quux</xv></string> |
| </a> |
| </object> |
| </xt></td> |
| <td class='code'><xt> |
| <object><xv>foo</xv><X <xa>b</xa>=<xs>'bar'</xs>/><xv>baz</xv><Y <xa>c</xa>=<xs>'qux'</xs>/><xv>quux</xv></object> |
| </xt></td> |
| </tr> |
| </table> |
| <p> |
| Whitespace (tabs and newlines) are not added to MIXED child nodes in readable-output mode. |
| This helps ensures strings in the serialized output can be losslessly parsed back into their original |
| forms when they contain whitespace characters. |
| If the {@link javax.xml.stream.XMLInputFactory#IS_REPLACING_ENTITY_REFERENCES} setting was not useless |
| in Java, we could support lossless readable XML for MIXED content. |
| But as of Java 8, it still does not work. |
| </p> |
| <p> |
| XML suffers from other deficiencies as well that affect MIXED content. |
| For example, <xt><X></X></xt> and <xt><X/></xt> are equivalent in XML and |
| indistinguishable by the Java XML parsers. |
| This makes it impossible to differentiate between an empty element and an element containing an empty |
| string. |
| This causes empty strings to get lost in translation. |
| To alleviate this, we use the constructs <js>"_xE000_"</js> to represent an empty string, and |
| <js>"_x0020_"</js> to represent leading and trailing spaces. |
| </p> |
| <p> |
| The examples below show how whitespace is handled under various circumstances: |
| </p> |
| <table class='styled w800'> |
| <tr> |
| <th>Data type</th> |
| <th>XML</th> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>TEXT</jsf>) |
| <jk>public</jk> String a = <jk>null</jk>; |
| } |
| </td> |
| <td class='code'><xt> |
| <X/> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>TEXT</jsf>) |
| <jk>public</jk> String a = <js>""</js>; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv>_xE000_</xv></X> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>TEXT</jsf>) |
| <jk>public</jk> String a = <js>" "</js>; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv>_x0020_</xv></X> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>TEXT</jsf>) |
| <jk>public</jk> String a = <js>" "</js>; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv>_x0020__x0020_</xv></X> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>TEXT</jsf>) |
| <jk>public</jk> String a = <js>" foobar "</js>; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv>_x0020_ foobar _x0020_</xv></X> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>TEXT_PWS</jsf>) |
| <jk>public</jk> String a = <jk>null</jk>; |
| } |
| </td> |
| <td class='code'><xt> |
| <X/> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>TEXT_PWS</jsf>) |
| <jk>public</jk> String a = <js>""</js>; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv>_xE000_</xv></X> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>TEXT_PWS</jsf>) |
| <jk>public</jk> String a = <js>" "</js>; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv> </xv></X> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>TEXT_PWS</jsf>) |
| <jk>public</jk> String a = <js>" "</js>; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv> </xv></X> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>TEXT_PWS</jsf>) |
| <jk>public</jk> String a = <js>" foobar "</js>; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv> foobar </xv></X> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>MIXED</jsf>) |
| <jk>public</jk> String[] a = <jk>null</jk>; |
| } |
| </td> |
| <td class='code'><xt> |
| <X/> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>MIXED</jsf>) |
| <jk>public</jk> String a[] = <jk>new</jk> String[]{<js>""</js>}; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv>_xE000_</xv></X> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>MIXED</jsf>) |
| <jk>public</jk> String a[] = <jk>new</jk> String[]{<js>" "</js>}; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv>_x0020_</xv></X> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>MIXED</jsf>) |
| <jk>public</jk> String a[] = <jk>new</jk> String[]{<js>" "</js>}; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv>_x0020__x0020_</xv></X> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>MIXED</jsf>) |
| <jk>public</jk> String a[] = <jk>new</jk> String[]{ |
| <js>" foobar "</js> |
| }; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv>_x0020_ foobar _x0020_</xv></X> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>MIXED_PWS</jsf>) |
| <jk>public</jk> String[] a = <jk>null</jk>; |
| } |
| </td> |
| <td class='code'><xt> |
| <X/> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>MIXED_PWS</jsf>) |
| <jk>public</jk> String a[] = <jk>new</jk> String[]{<js>""</js>}; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv>_xE000_</xv></X> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>MIXED_PWS</jsf>) |
| <jk>public</jk> String a[] = <jk>new</jk> String[]{<js>" "</js>}; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv> </xv></X> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>MIXED_PWS</jsf>) |
| <jk>public</jk> String a[] = <jk>new</jk> String[]{<js>" "</js>}; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv> </xv></X> |
| </xt></td> |
| </tr> |
| <tr> |
| <td class='code'> |
| <ja>@Bean</ja>(typeName=<js>"X"</js>) |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>MIXED_PWS</jsf>) |
| <jk>public</jk> String a[] = <jk>new</jk> String[]{ |
| <js>" foobar "</js> |
| }; |
| } |
| </td> |
| <td class='code'><xt> |
| <X><xv> foobar </xv></X> |
| </xt></td> |
| </tr> |
| </table> |
| |
| <p> |
| It should be noted that when using <jsf>MIXED</jsf>, you are not guaranteed to parse back the exact |
| same content since side-by-side strings in the content will end up concatenated when parsed. |
| </p> |
| <p> |
| The {@link oaj.xml.annotation.XmlFormat#TEXT} format is similar to |
| {@link oaj.xml.annotation.XmlFormat#MIXED} except it's meant for solitary objects that |
| get serialized as simple child text nodes. |
| Any object that can be serialize to a <c>String</c> can be used. |
| The {@link oaj.xml.annotation.XmlFormat#TEXT_PWS} is the same except whitespace is |
| preserved in the output. |
| </p> |
| <table class='styled w800'> |
| <tr> |
| <th>Data type</th> |
| <th>JSON example</th> |
| <th>Without annotations</th> |
| <th>With annotations</th> |
| </tr> |
| <tr> |
| <td class='code'> |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>TEXT</jsf>) |
| <jk>public</jk> String a; |
| } |
| </td> |
| <td class='code'> |
| { |
| a: <js>'foo'</js> |
| } |
| </td> |
| <td class='code'><xt> |
| <object> |
| <a><xv>foo</xv></a> |
| </object> |
| </xt></td> |
| <td class='code'><xt> |
| <object><xv>foo</xv></object> |
| </xt></td> |
| </tr> |
| </table> |
| <p> |
| The {@link oaj.xml.annotation.XmlFormat#XMLTEXT} format is similar to |
| {@link oaj.xml.annotation.XmlFormat#TEXT} except it's meant for strings containing XML |
| that should be serialized as-is to the document. |
| Any object that can be serialize to a <c>String</c> can be used. |
| During parsing, the element content gets parsed with the rest of the document and then re-serialized to |
| XML before being set as the property value. |
| This process may not be perfect (e.g. double quotes may be replaced by single quotes, etc...). |
| </p> |
| <table class='styled w800'> |
| <tr> |
| <th>Data type</th> |
| <th>JSON example</th> |
| <th>With TEXT annotation</th> |
| <th>With XMLTEXT annotation</th> |
| </tr> |
| <tr> |
| <td class='code'> |
| <jk>class</jk> MyBean { |
| <ja>@Xml</ja>(format=XmlFormat.<jsf>XMLTEXT</jsf>) |
| <jk>public</jk> String a; |
| } |
| </td> |
| <td class='code'> |
| { |
| a: <js>'Some <b>XML</b> text'</js> |
| } |
| </td> |
| <td class='code'><xt> |
| <object><xv>Some &lt;b&gt;XML&lt;/b&gt; text</xv></object> |
| </xt></td> |
| <td class='code'><xt> |
| <object><xv>Some <xt><b></xt>XML<xt></b></xt> text</xv></object> |
| </xt></td> |
| </tr> |
| </table> |