Skip to main content

juneau-bean

Maven
<dependency>
<groupId>org.apache.juneau</groupId>
<artifactId>juneau-bean</artifactId>
<version>${juneau.version}</version>
</dependency>
Jarjuneau-bean-10.0.0.jar
OSGiorg.apache.juneau.bean_10.0.0.jar
LinksMaven 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.

ModuleDescription
juneau-bean-html5HTML5 DOM element beans for building HTML fragments and documents as POJOs.
juneau-bean-atomAtom syndication feed beans (RFC 4287).
juneau-bean-jsonschemaJSON Schema (Draft 2020-12) beans, generator bridge, and validator.
juneau-bean-openapi-v3OpenAPI 3.0 document and UI beans.
juneau-bean-commonShared general-purpose DTOs (LinkString, ResultSetList).
juneau-bean-swagger-v2Swagger 2.0 document and UI beans.
juneau-bean-mcp-v20250618Model Context Protocol (MCP) 2025-06-18 wire beans (JSON-RPC envelope lives in juneau-bean-jsonrpc).
juneau-bean-mcp-v20260728Model 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-jsonrpcRevision-neutral JSON-RPC 2.0 envelope beans (JsonRpcRequest, JsonRpcResponse, JsonRpcError, McpException).
juneau-bean-rfc7807RFC 7807 Problem Details (application/problem+json) beans.
juneau-bean-halHAL hypermedia (application/hal+json) beans.
juneau-bean-jsonapiJSON:API v1.1 (application/vnd.api+json) beans.
juneau-bean-jsonpatchJSON 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.

Examples
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>
See Also

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.

Example
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);
See Also

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.

Example
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();
See Also

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:

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

See Also

Swagger UI for more information.