juneau-bean-common
The juneau-bean-common module provides a small set of general-purpose Data Transfer Object (DTO) beans in the org.apache.juneau.bean package that don't belong to any single wire-format module.
Overview
Unlike the format-specific bean modules (juneau-bean-atom, juneau-bean-hal, and so on), this module isn't a base library that the other juneau-bean-X modules build on — each of those depends directly on juneau-marshall, not on this module. Instead, juneau-bean-common ships a couple of reusable DTOs that are consumed by higher-level modules such as juneau-rest-server and the Juneau examples.
Its only runtime dependency is juneau-marshall.
Bean Classes
| Class | Purpose |
|---|---|
LinkString | A simple hyperlink bean. Renders as an HTML <a href='...'>name</a> anchor when serialized with the HTML serializer, and as a plain bean in all other formats. |
ResultSetList | Transforms a JDBC ResultSet into a List<Map<String,Object>> for easy serialization. Reads the entire result set into memory and closes it. |
LinkString
LinkString is annotated with @HtmlLink, so the HTML serializer converts it into a hyperlink while every other serializer treats it as an ordinary two-property bean (name and uri).
import org.apache.juneau.bean.*;
import org.apache.juneau.marshall.html.*;
LinkString link = new LinkString("Apache Juneau", "https://juneau.apache.org");
// HTML output: <a href='https://juneau.apache.org'>Apache Juneau</a>
String html = HtmlSerializer.DEFAULT.write(link);
The uri accepts printf-style (String.format) arguments for parameterized links:
LinkString view = new LinkString("View", "/items/%s", itemId);
ResultSetList
ResultSetList extends LinkedList<Map<String,Object>>, giving you a directly-serializable snapshot of a SQL query result:
import org.apache.juneau.bean.*;
import org.apache.juneau.marshall.json.*;
try (ResultSet rs = statement.executeQuery("SELECT id, name FROM users")) {
// Load rows starting at position 1, with no cap, and no synthetic row-number column.
ResultSetList rows = new ResultSetList(rs, 1, Integer.MAX_VALUE, false);
String json = JsonSerializer.DEFAULT.write(rows);
// [{"id":1,"name":"..."},{"id":2,"name":"..."}]
}
Large binary/character columns (BLOB, CLOB, LONGVARBINARY, etc.) are summarized rather than fully materialized.
Dependencies
- Runtime:
juneau-marshall - External: None
- Used by:
juneau-rest-serverand the Juneau examples (not by the otherjuneau-bean-Xmodules)