| <!-- |
| /*************************************************************************************************************************** |
| * 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 Details |
| |
| <p> |
| Juneau supports converting arbitrary POJOs to and from XML using ultra-efficient serializers and parsers. |
| The XML serializer converts POJOs directly to XML without the need for intermediate DOM objects. |
| Likewise, the XML parser uses a STaX parser and creates POJOs directly without intermediate DOM objects. |
| </p> |
| <p> |
| Unlike frameworks such as JAXB, Juneau does not require POJO classes to be annotated to produce and consume |
| XML. |
| However, several XML annotations are provided for handling namespaces and fine-tuning the format of the XML produced. |
| </p> |
| <p> |
| The following example shows XML for a typical bean: |
| </p> |
| <h5 class='figure'>Sample Beans</h5> |
| <p class='bpcode w800'> |
| <ja>@Bean</ja>(typeName=<js>"person"</js>) |
| <jk>public class</jk> Person { |
| |
| <jc>// Bean properties</jc> |
| <jk>public</jk> String <jf>name</jf>; |
| <ja>@Swap</ja>(TemporalCalendarSwap.IsoInstant.<jk>class</jk>) <jk>public</jk> Calendar <jf>birthDate</jf>; |
| <jk>public</jk> List<Address> <jf>addresses</jf>; |
| |
| <jc>// Getters/setters omitted</jc> |
| } |
| |
| <ja>@Bean</ja>(typeName=<js>"address"</js>) |
| <jk>public class</jk> Address { |
| |
| <jc>// Bean properties</jc> |
| <jk>public</jk> String <jf>street</jf>, <jf>city</jf>; |
| <jk>public</jk> StateEnum <jf>state</jf>; |
| <jk>public int</jk> <jf>zip</jf>; |
| <jk>public boolean</jk> <jf>isCurrent</jf>; |
| |
| <jc>// Getters/setters omitted</jc> |
| } |
| </p> |
| <h5 class='figure'>Sample Code</h5> |
| <p class='bpcode w800'> |
| Person p = <jk>new</jk> Person() |
| .name(<js>"John Smith"</js>) |
| .birthDate(<js>"1946-08-12T00:00:00Z"</js>) |
| .addresses( |
| <jk>new</jk> Address() |
| .street(<js>"100 Main Street"</js>) |
| .city(<js>"Anywhereville"</js>) |
| .state(<jsf>NY</jsf>) |
| .zip(12345) |
| .isCurrent(<jk>true</jk>); |
| ); |
| </p> |
| <h5 class='figure'>Normal XML:</h5> |
| <p class='bpcode w800'> |
| <xt><person></xt> |
| <xt><name></xt>John Smith<xt></name></xt> |
| <xt><birthDate></xt>1946-08-12T04:00:00Z<xt></birthDate></xt> |
| <xt><addresses></xt> |
| <xt><address></xt> |
| <xt><street></xt>100 Main Street<xt></street></xt> |
| <xt><city></xt>Anywhereville<xt></city></xt> |
| <xt><state></xt>NY<xt></state></xt> |
| <xt><zip></xt>12345<xt></zip></xt> |
| <xt><isCurrent></xt>true<xt></isCurrent></xt> |
| <xt></address></xt> |
| <xt></addresses></xt> |
| <xt></person></xt> |
| </p> |
| <p> |
| Juneau produces JSON-equivalent XML, meaning any valid JSON document can be losslessly converted into an XML |
| equivalent. |
| In fact, all of the Juneau serializers and parsers are built upon this JSON-equivalence. |
| </p> |