Skip to main content

API Reference

mjml-java exports five packages through its Java module dev.jcputney.mjml. This section documents the public API surface you interact with directly.

Module Exports

PackageDescription
dev.jcputney.mjmlCore API: renderer, configuration, exceptions, include resolver
dev.jcputney.mjml.cssStandalone CSS inlining engine
dev.jcputney.mjml.componentComponent base classes and factory interface for custom components
dev.jcputney.mjml.contextGlobal and render context (advanced/internal use)
dev.jcputney.mjml.parserMJML parser and AST node types (advanced/internal use)

For most use cases, you only need the dev.jcputney.mjml package.

Class Diagram

Exception Hierarchy

All exceptions are unchecked (extend RuntimeException), so you are not forced to catch them. Use targeted catch blocks when you need to distinguish between error types.

ExceptionThrown When
MjmlParseExceptionMalformed XML, missing <mjml> root element, invalid structure
MjmlValidationExceptionInput exceeds maxInputSize or nesting exceeds maxNestingDepth
MjmlIncludeExceptionInclude file not found, path traversal attempt, circular includes
MjmlRenderExceptionUnexpected error during the render phase
MjmlExceptionBase type -- catch this to handle all MJML errors
try {
MjmlRenderResult result = MjmlRenderer.render(userInput);
} catch (MjmlParseException e) {
// Invalid MJML structure
} catch (MjmlValidationException e) {
// Input too large or too deeply nested
} catch (MjmlIncludeException e) {
// Include resolution failed
} catch (MjmlRenderException e) {
// Unexpected error during render phase
} catch (MjmlException e) {
// Catch-all for any MJML error
}