juneau-bean
| Maven | |
|---|---|
| Jar | juneau-bean-10.0.0.jar |
| OSGi | org.apache.juneau.bean_10.0.0.jar |
| Links | Maven Central · Javadocs · Source |
Contents/Features
- Predefined POJOs for generating commonly-used document types.
Overview
The juneau-bean libraries contain several predefined POJOs for generating commonly-used document types that are designed to be used with the Juneau Marshaller APIs for both serializing and parsing.
Modules
The juneau-bean group is split into one module per document type. Every module depends only on juneau-marshall, so its beans round-trip through any Juneau serializer/parser.
| Module | Description |
|---|---|
| juneau-bean-html5 | HTML5 DOM element beans for building HTML fragments and documents as POJOs. |
| juneau-bean-atom | Atom syndication feed beans (RFC 4287). |
| juneau-bean-jsonschema | JSON Schema (Draft 2020-12) beans, generator bridge, and validator. |
| juneau-bean-openapi-v3 | OpenAPI 3.0 document and UI beans. |
| juneau-bean-common | Shared general-purpose DTOs (LinkString, ResultSetList). |
| juneau-bean-swagger-v2 | Swagger 2.0 document and UI beans. |
| juneau-bean-mcp-v20250618 | Model Context Protocol (MCP) 2025-06-18 wire beans (JSON-RPC envelope lives in juneau-bean-jsonrpc). |
| juneau-bean-mcp-v20260728 | Model Context Protocol (MCP) 2026-07-28 wire beans (package org.apache.juneau.bean.mcp.v20260728): request/result metadata, cache hints, multi-round-trip requests, elicitation, sampling, and subscriptions. Documented alongside the 2025-06-18 beans on the same page. |
| juneau-bean-jsonrpc | Revision-neutral JSON-RPC 2.0 envelope beans (JsonRpcRequest, JsonRpcResponse, JsonRpcError, McpException). |
| juneau-bean-rfc7807 | RFC 7807 Problem Details (application/problem+json) beans. |
| juneau-bean-hal | HAL hypermedia (application/hal+json) beans. |
| juneau-bean-jsonapi | JSON:API v1.1 (application/vnd.api+json) beans. |
| juneau-bean-jsonpatch | JSON Patch (RFC 6902) beans. |
The sections below highlight a few of these modules; see each module's page for full coverage.
HTML5
The Juneau HTML5 DTO beans are simply beans with fluent-style setters that allow you to quickly construct HTML fragments as Java objects. These objects can then be serialized to HTML using one of the existing HTML serializers, or to other languages such as JSON using the JSON serializers.
The HtmlBuilder class is a utility class with predefined static methods that allow you to easily construct DTO bean instances in a minimal amount of code.
import static org.apache.juneau.bean.html5.HtmlBuilder.*;
// An HTML table
Object mytable =
table(
tr(
th("c1"),
th("c2")
),
tr(
td("v1"),
td("v2")
)
);
String html = Html.of(mytable);
<table>
<tr>
<th>c1</th>
<th>c2</th>
</tr>
<tr>
<td>v1</td>
<td>v2</td>
</tr>
</table>
HTML5 for more information.
ATOM
The Juneau ATOM feed DTO beans are simply beans with fluent-style setters. The following code shows a feed being created programmatically using the AtomBuilder class.
import static org.apache.juneau.bean.atom.AtomBuilder.*;
Feed feed =
feed("tag:juneau.apache.org", "Juneau ATOM specification", "2016-01-02T03:04:05Z")
.setSubtitle(text("html").setText("Describes stuff about Juneau"))
.setLinks(
link("alternate", "text/html", "http://juneau.apache.org").setHreflang("en"),
link("self", "application/atom+xml", "http://juneau.apache.org/feed.atom")
)
.setRights("Copyright (c) ...")
.setGenerator(
generator("Juneau").setUri("http://juneau.apache.org/").setVersion("1.0")
)
.setEntries(
entry("tag:juneau.sample.com,2013:1.2345", "Juneau ATOM specification snapshot", "2016-01-02T03:04:05Z")
.setLinks(
link("alternate", "text/html", "http://juneau.apache.org/juneau.atom"),
link("enclosure", "audio/mpeg", "http://juneau.apache.org/audio/juneau_podcast.mp3").setLength(1337)
)
.setPublished("2016-01-02T03:04:05Z")
.setAuthors(
person("Jane Smith").setUri("http://juneau.apache.org/").setEmail("janesmith@apache.org")
)
.setContributors(
person("John Smith")
)
.setContent(
content("xhtml")
.setLang("en")
.setBase("http://www.apache.org/")
.setText("[Update: Juneau supports ATOM.]")
)
);
// Create a serializer with readable output, no namespaces yet.
XmlSerializer serializer = XmlSerializer.create().sq().ws().build();
// Serialize to ATOM/XML
String atomXml = serializer.write(feed);
Atom for more information.
Swagger
The Juneau Swagger DTO beans are simply beans with fluent-style setters that allow you to quickly construct Swagger documents as Java objects. These objects can then be serialized to JSON using one of the existing JSON serializers, or to other languages such as XML or HTML using the other serializers.
import static org.apache.juneau.bean.swagger.SwaggerBuilder.*;
import java.net.URI;
Swagger swagger = swagger()
.setSwagger("2.0")
.setInfo(
info("Swagger Petstore", "1.0.0")
.setDescription("This is a sample server Petstore server.")
.setTermsOfService("http://swagger.io/terms/")
.setContact(
contact().setEmail("apiteam@swagger.io")
)
.setLicense(
license("Apache 2.0", URI.create("http://www.apache.org/licenses/LICENSE-2.0.html"))
)
)
.setHost("petstore.swagger.io")
.setBasePath("/v2")
.setTags(
tag("pet").setDescription("Everything about your Pets")
.setExternalDocs(
externalDocumentation("http://swagger.io", "Find out more")
)
)
.addSchemes("http")
.addOperation("/pet", "post",
operation()
.setTags("pet")
.setSummary("Add a new pet to the store")
.setDescription("")
.setOperationId("addPet")
.addConsumes(MediaType.JSON, MediaType.XML)
.addProduces(MediaType.JSON, MediaType.XML)
.setParameters(
parameterInfo("body", "body")
.setDescription("Pet object that needs to be added to the store")
.setRequired(true)
)
.addResponse("405", responseInfo("Invalid input"))
);
// Serialize using JSON serializer.
String swaggerJson = Json.of(swagger);
// Or just use toString() or asJson().
swaggerJson = swagger.asJson();
Swagger for more information.
SwaggerUI
The SwaggerUI class is a DTO bean class for generating Swagger user interfaces from Swagger beans.
The PetStore example described later provides an example of auto-generated Swagger JSON:

Using SwaggerUI, we're able to render that JSON as a Swagger user interface when the request is asking for HTML:

Swagger UI for more information.