Skip navigation links

Package org.apache.juneau.html

HTML serialization and parsing support

See: Description

Package org.apache.juneau.html Description

HTML serialization and parsing support

Table of Contents
  1. HTML serialization support

  2. HTML parsing support

1 - HTML serialization support

1.1 - HTML support methodology

The following examples show how different data types are represented in HTML. They mirror how the data structures are represented in JSON.

Simple types

The representation for simple types mirror those produced by the XML serializer. Tags are added to help differentiate data types when they cannot be inferred through reflection. These tags are ignored by browsers and treated as plain text.

Data type JSON example HTML
string 'foo' <string>foo</string>
boolean true <boolean>true</boolean>
integer 123 <number>123</number>
float 1.23 <number>1.23</number>
null null <null/>
Maps

Maps and beans are represented as tables.

The _type attribute is added to differentiate between objects (maps/beans) and arrays (arrays/collections).

Data type JSON example HTML
Map<String,String> { k1: 'v1' k2: null } <table _type='object'> <tr> <td>k1</td> <td>v1</td> </tr> <tr> <td>k2</td> <td><null/></td> </tr> </table>
Map<String,Number> { k1: 123, k2: 1.23, k3: null } <table _type='object'> <tr> <td>k1</td> <td>123</td> </tr> <tr> <td>k2</td> <td>1.23</td> </tr> <tr> <td>k3</td> <td><null/></td> </tr> </table>
Map<String,Object> { k1: 'v1' k2: 123, k3: 1.23, k4: true, k5: null } <table _type='object'> <tr> <td>k1</td> <td>v1</td> </tr> <tr> <td>k2</td> <td><number>123</number></td> </tr> <tr> <td>k3</td> <td><number>1.23</number></td> </tr> <tr> <td>k4</td> <td><boolean>true</boolean></td> </tr> <tr> <td>k5</td> <td><null/></td> </tr> </table>
Arrays

Collections and arrays are represented as ordered lists.

Data type JSON example HTML
String[] [ 'foo' null ] <ul> <li>foo</li> <li><null/></li> </ul>
Number[] [ 123, 1.23, null ] <ul> <li>123</li> <li>1.23</li> <li><null/></li> </ul>
Object[] [ 'foo', 123, 1.23, true, null ] <ul> <li>foo</li> <li><number>123</number></li> <li><number>1.23</number></li> <li><boolean>true</boolean></li> <li><null/></li> </ul>
String[][] [ ['foo', null], null, ] <ul> <li> <ul> <li>foo</li> <li><null/></li> </ul> </li> <li><null/></li> </ul>
int[] [ 123 ] <ul> <li>123</li> </ul>
boolean[] [ true ] <ul> <li>true</li> </ul>
Collections
Data type JSON example HTML
List<String> [ 'foo' null ] <ul> <li>foo</li> <li><null/></li> </ul>
List<Number> [ 123, 1.23, null ] <ul> <li>123</li> <li>1.23</li> <li><null/></li> </ul>
List<Object> [ 'foo', 123, 1.23, true, null ] <ul> <li>foo</li> <li><number>123</number></li> <li><number>1.23</number></li> <li><boolean>true</boolean></li> <li><null/></li> </ul>
Beans
Data type JSON example HTML
class MyBean { public String a; public int b; public Object c; // String value public Object d; // Integer value public MyBean2 e; public String[] f; public int[] g; } class MyBean2 { String h; } { a: 'foo', b: 123, c: 'bar', d: 456, e: { h: 'baz' } f: ['qux'] g: [789] } <table _type='object'> <tr> <td>a</td> <td>foo</td> </tr> <tr> <td>b</td> <td>123</td> </tr> <tr> <td>c</td> <td>bar</td> </tr> <tr> <td>d</td> <td><number>456</number></td> </tr> <tr> <td>e</td> <td> <table _type='object'> <tr> <td>h</td> <td>qux</td> </tr> </table> </td> </tr> <tr> <td>f</td> <td> <ul> <li>baz</li> </ul> </td> </tr> <tr> <td>g</td> <td> <ul> <li>789</li> </ul> </td> </tr> </table>
Beans with Map properties
Data type JSON example HTML
class MyBean { public Map<String,String> a; public Map<String,Number> b; public Map<String,Object> c; } { a: { k1: 'foo' }, b: { k2: 123 }, c: { k3: 'bar', k4: 456, k5: true, k6: null } } <table _type='object'> <tr> <td>a</td> <td> <table _type='object'> <tr> <td>k1</td> <td>foo</td> </tr> </table> </td> </tr> <tr> <td>b</td> <td> <table _type='object'> <tr> <td>k2</td> <td>123</td> </tr> </table> </td> </tr> <tr> <td>c</td> <td> <table _type='object'> <tr> <td>k3</td> <td>bar</td> </tr> <tr> <td>k4</td> <td><number>456</number></td> </tr> <tr> <td>k5</td> <td><boolean>true</boolean></td> </tr> <tr> <td>k6</td> <td><null/></td> </tr> </table> </td> </tr> </table>
TODO - Special characters - \n\t\b\f TODO BeanWithPropertiesWithTypeNames... TODO

2 - HTML parsing support

The parser will handle anything produced by the serializer.
Skip navigation links

Copyright © 2017 Apache. All rights reserved.