Skip to main content

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.

Looking for a full application?

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.

FormatExample class(es)Demonstrates
JSONcore/json/JsonSimpleExample, JsonComplexExample, JsonConfigurationExampleJsonSerializer/JsonParser and Json5Serializer, generic-map parsing, and building serializers/parsers with custom configuration.
XMLcore/xml/XmlSimpleExample, XmlComplexExample, XmlConfigurationExampleXmlSerializer/XmlParser over simple and nested/collection POJOs, plus custom configuration.
HTMLcore/html/HtmlSimpleExample, HtmlComplexExampleHtmlSerializer/HtmlParser and HtmlDocSerializer (full-document output).
UONcore/uon/UonExample, UonComplexExampleUonSerializer/UonParser round-trips.
OpenAPIcore/oapi/OapiExampleOpenApiSerializer/OpenApiParser plus HttpPartSchema-driven HTTP-part serialization.

Beans / DTOs​

Example classDemonstrates
bean/BeanExampleBuilding 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, AtomHtmlExampleSerializing the shared AtomFeed bean to ATOM/XML, JSON, and HTML.

Other APIs​

Example classDemonstrates
core/svl/SvlExampleResolving $E{}/$S{} variables and #{...} functions with VarResolver.DEFAULT.
core/config/store/SqlStoreA skeleton ConfigStore backed by a relational database (a builder + polling watcher; the JDBC read methods are left as // Implement me! exercises).
serializer/ImageSerializerA custom OutputStreamSerializer that writes BufferedImage objects as image/png / image/jpeg.
parser/ImageParserA 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.

Juneau Marshall - Core marshalling concepts behind these examplesMarshallers - The serializer/parser API surface used throughoutJSON - JSON marshalling documentationXML - XML marshalling documentationHTML - HTML marshalling documentationUON - UON marshalling documentationOpenApi - OpenAPI marshalling documentationSimple Variable Language - The SVL API used by SvlExamplejuneau-bean-atom - The ATOM bean model used by the ATOM examplesjuneau-config - The configuration API behind SqlStorejuneau-petstore - A full REST showcase application building on these core APIsjuneau-examples-mcp - MCP server/client examples (including OAuth-secured and Spring Boot variants)Juneau Ecosystem Overview - How the modules fit together

Source Code​

The complete source for all examples is in the juneau-examples-core module of the Apache Juneau project.