Is there an existing open-source Java or JSTL tag library that will render the contents of a passed-in object as HTML content? I’m thinking of an object like this:
Object Cat {
String name;
Integer age;
String color;
Coat coat; // Enum: LONG/MEDIUM/SHORT
}
Ideally you could pass in a Cat object and get back an HTML representation of the object’s contents, perhaps with clickable links to expand/collapse content:
<H1>Object Type: Cat </H1>
<ul>
<li><span>name</span><span>"Fluffy"</span></li>
<li><span>age</span><span> 9</span></li>
<li><span>color</span><span> "Tabby"</span></li>
<li><span>coat</span><span> LONG</span></li>
</ul>
Seems like something that someone might have already written. I would hate to reinvent the wheel.
You may try Xstream library. It converts your java code to xml. Using XSLT, you can convert your xml to html format (Simple xml transformation using xslt is here – XML Transformations).