juneau-examples
The juneau-examples-core module is a collection of small, standalone main() programs that demonstrate Apache Juneau's core marshalling APIs — serializing Plain Old Java Objects (POJOs) to a format and parsing them back — plus a few extension points (a custom serializer/parser and a custom config store). Each example is self-contained: run it directly and read the inline comments showing the expected output.
The examples here are small main() programs for marshalling and MCP. For a complete, runnable REST
application with browsable HTML views, Mustache and FreeMarker view resources, a React single-page UI,
and typed clients, see the Petstore. For a minimal deployable app, see the
Starter Projects.
Module layout
juneau-examples/ (aggregator, packaging=pom)
├── juneau-examples-core/ Standalone core-marshalling examples (OSGi bundle)
│ └── src/main/java/org/apache/juneau/examples/
│ ├── core/pojo/ Shared sample beans (Pojo, PojoComplex)
│ ├── core/json/ JSON serialize/parse
│ ├── core/xml/ XML serialize/parse
│ ├── core/html/ HTML serialize/parse
│ ├── core/uon/ UON serialize/parse
│ ├── core/oapi/ OpenAPI HTTP-part serialization
│ ├── core/svl/ Simple Variable Language (SVL)
│ ├── core/config/store/ Custom ConfigStore (SqlStore skeleton)
│ ├── bean/ DTO builders (HTML5, ATOM, Swagger)
│ ├── bean/atom/ ATOM feed marshalling (XML/JSON/HTML)
│ ├── serializer/ Custom stream serializer (ImageSerializer)
│ └── parser/ Custom stream parser (ImageParser)
└── juneau-examples-mcp/ Model Context Protocol server/client examples
└── src/main/java/org/apache/juneau/examples/mcp/
├── (root) ExampleServer/ExampleMcpServer/ExampleClient, NoteStore
├── secured/ OAuth-secured MCP server/client + OfflineAuthorizationServer
└── spring/ Spring Boot MCP server integration
The juneau-examples-core module builds as an OSGi bundle and depends only on library Juneau modules — there is no runtime server or web container involved. juneau-examples-mcp is a separate, Rest-server-backed module; see Juneau MCP Recipes for its walkthrough.
Getting started
The ${juneau.version} property is 10.0.0-SNAPSHOT for these docs; the latest release on Maven Central is 9.2.0. See Install Juneau.
The examples build from the Juneau reactor. To exercise the same APIs in your own project, add the marshall dependency (the examples also pull in the bean and config modules used by specific examples):
<dependency>
<groupId>org.apache.juneau</groupId>
<artifactId>juneau-marshall</artifactId>
<version>${juneau.version}</version>
</dependency>
The example module additionally depends on juneau-commons, juneau-bean-atom, juneau-bean-common, juneau-bean-html5, juneau-bean-jsonschema, juneau-bean-swagger-v2, and juneau-config for the DTO and configuration examples.
Example catalog
Format marshalling
Each format example serializes the shared Pojo/PojoComplex bean and parses it back, asserting round-trip equality.
| Format | Example class(es) | Demonstrates |
|---|---|---|
| JSON | core/json/JsonSimpleExample, JsonComplexExample, JsonConfigurationExample | JsonSerializer/JsonParser and Json5Serializer, generic-map parsing, and building serializers/parsers with custom configuration. |
| XML | core/xml/XmlSimpleExample, XmlComplexExample, XmlConfigurationExample | XmlSerializer/XmlParser over simple and nested/collection POJOs, plus custom configuration. |
| HTML | core/html/HtmlSimpleExample, HtmlComplexExample | HtmlSerializer/HtmlParser and HtmlDocSerializer (full-document output). |
| UON | core/uon/UonExample, UonComplexExample | UonSerializer/UonParser round-trips. |
| OpenAPI | core/oapi/OapiExample | OpenApiSerializer/OpenApiParser plus HttpPartSchema-driven HTTP-part serialization. |
Beans / DTOs
| Example class | Demonstrates |
|---|---|
bean/BeanExample | Building HTML5 tables/forms with HtmlBuilder, an ATOM feed with AtomBuilder, and a Swagger document with SwaggerBuilder, then serializing them to HTML/JSON. |
bean/atom/AtomXmlExample, AtomJsonExample, AtomHtmlExample | Serializing the shared AtomFeed bean to ATOM/XML, JSON, and HTML. |
Other APIs
| Example class | Demonstrates |
|---|---|
core/svl/SvlExample | Resolving $E{}/$S{} variables and #{...} functions with VarResolver.DEFAULT. |
core/config/store/SqlStore | A skeleton ConfigStore backed by a relational database (a builder + polling watcher; the JDBC read methods are left as // Implement me! exercises). |
serializer/ImageSerializer | A custom OutputStreamSerializer that writes BufferedImage objects as image/png / image/jpeg. |
parser/ImageParser | A custom InputStreamParser that reads image/png / image/jpg byte streams back into BufferedImage. |
Running the examples
Every example class exposes a public static void main(String[] args) entry point and can be launched directly from an IDE or with java once the module is on the classpath. There is no shared launcher or server — pick a class and run it. Most print their output via java.util.logging, and each class documents its expected output in inline comments.
The immutable-POJO pattern
The shared sample bean shows the pattern most format examples rely on — an immutable POJO whose constructor is annotated so Juneau can reconstruct it during parsing:
public class Pojo {
private final String id;
private final String name;
@BeanCtor
public Pojo(@Name("id") String id, @Name("name") String name) {
this.id = id;
this.name = name;
}
public String getId() { return id; }
public String getName() { return name; }
}
Because the constructor is marked @BeanCtor with @Name-annotated parameters, the same bean round-trips through every format (JSON, XML, HTML, UON, OpenAPI) without setters, letting your domain objects stay immutable.
Related Documentation
SvlExampleSqlStoreSource Code
The complete source for all examples is in the juneau-examples-core module of the Apache Juneau project.