Quick Start Guide

Get up and running with MetaObjects in minutes

Step 1: Add Dependency

Add the MetaObjects dependency to your Maven project:

<dependency>
  <groupId>com.draagon.metaobjects</groupId>
  <artifactId>metaobjects-core</artifactId>
  <version>5.1.0</version>
</dependency>

Step 2: Define Metadata

Create a metadata/model.json file with your object definitions:

{
  "metadata": {
    "package": "com.example",
    "children": [
      {
        "object": {
          "name": "User",
          "type": "pojo",
          "children": [
            {"field": {"name": "id", "type": "long"}},
            {"field": {"name": "email", "type": "string"}},
            {"field": {"name": "name", "type": "string"}}
          ]
        }
      }
    ]
  }
}

Step 3: Configure Maven Plugin

Add the MetaObjects Maven plugin to generate code during build:

<plugin>
  <groupId>com.draagon.metaobjects</groupId>
  <artifactId>metaobjects-maven-plugin</artifactId>
  <version>5.1.0</version>
  <configuration>
    <generators>
      <generator>
        <className>com.draagon.meta.generator.JavaInterfaceGenerator</className>
      </generator>
    </generators>
  </configuration>
</plugin>

Step 4: Generate Code

Run the Maven plugin to generate your code:

mvn metaobjects:generate

Step 5: Use Generated Code

Import and use the generated classes in your application:

// Load metadata with proper configuration
FileMetaDataLoader loader = new FileMetaDataLoader(
    new FileLoaderOptions()
        .addParser("*.json", JsonMetaDataParser.class)
        .addSources(new LocalFileMetaDataSources(
            Arrays.asList(
                "com/draagon/meta/loader/xml/metaobjects.types.json",
                "metadata/users/user.metadata.json"
            )
        )),
    "user-example"
).init();

MetaObject userMeta = loader.getMetaObject("User");

// Create instance
Object user = userMeta.newInstance();
userMeta.setFieldValue(user, "email", "user@example.com");
userMeta.setFieldValue(user, "name", "John Doe");

// Validate
ValidationResult result = userMeta.performValidation(user);
if (result.isValid()) {
    System.out.println("User is valid!");
}

System Requirements

Technical specifications for MetaObjects

Runtime Requirements

  • Java 21 or higher
  • 512MB RAM minimum
  • 100MB disk space
  • Any JDBC-compatible database (optional)

Build Requirements

  • Maven 3.6 or higher
  • Java Development Kit (JDK) 21+
  • Git for version control
  • IDE support (IntelliJ, Eclipse, VS Code)

Supported Languages

  • Java (Full support)
  • TypeScript (Full support)
  • C# (Generation support)
  • Python (Generation support)
  • JavaScript (Generation support)

Supported Databases

  • PostgreSQL
  • MySQL / MariaDB
  • Oracle Database
  • Microsoft SQL Server
  • H2 Database
  • Any JDBC-compatible database

Architecture Overview

Understanding the core components of MetaObjects

Metadata Module

Core metadata models and types that define the foundation of the system.

  • Core metadata models and types
  • Base interfaces and abstractions
  • Exception hierarchy
  • Data type system

Maven Plugin Module

Build-time integration that generates code during your Maven build process.

  • Build-time code generation
  • Maven lifecycle integration
  • Generator framework
  • Configuration management

Core Module

Runtime components that power the metadata-driven behavior in your applications.

  • MetaObject implementations
  • Loader framework
  • Serialization system
  • Validation framework

Object Manager Module

High-level abstraction layer for data persistence and querying.

  • Persistence abstraction
  • Query framework
  • Expression system
  • Manager integration

Core API Reference

Key interfaces and classes you'll work with

MetaObject Interface

The core interface for working with metadata-driven objects.

  • newInstance() - Create new objects
  • getFieldValue() - Get field values
  • setFieldValue() - Set field values
  • performValidation() - Validate objects
  • getMetaFields() - Get field metadata

MetaDataLoader

Loads metadata definitions from various sources.

  • Load from JSON/XML files
  • Runtime metadata updates
  • Multiple source support
  • Classpath and file system loading

Validation Framework

Comprehensive validation system for data integrity.

  • Field-level validators
  • Object-level validators
  • Custom validation rules
  • Validation chains

Generator Framework

Extensible code generation system.

  • Pluggable generators
  • Custom templates
  • Multiple output formats
  • Build integration

Best Practices

Proven patterns for successful MetaObjects implementations

Metadata Organization

  • One package per domain
  • Logical grouping of objects
  • Clear naming conventions
  • Version control metadata

Development Workflow

  • Define metadata first
  • Generate code during build
  • Validate at runtime
  • Test with metadata

Production Deployment

  • Pre-load metadata at startup
  • Monitor metadata changes
  • Use overlay system for environments
  • Enable caching for performance

Performance Optimization

  • Cache metadata definitions
  • Use lazy loading for large datasets
  • Optimize serialization settings
  • Monitor memory usage

Common Use Cases

How to apply MetaObjects in different scenarios

REST API Development

Generate consistent DTOs and validation across services. Perfect for microservices architectures where multiple services need to share data models.

@RestController
public class UserController {
    
    @PostMapping("/users")
    public ResponseEntity<User> createUser(@Valid @RequestBody User user) {
        // Validation handled automatically by metadata
        return ResponseEntity.ok(userService.save(user));
    }
}

Database Entities

Generate JPA entities with proper annotations directly from your metadata definitions.

@Entity
@Table(name = "users")
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(nullable = false)
    private String email;
    
    // Generated getters and setters
}

Frontend Models

Generate TypeScript interfaces and validators for your frontend applications.

// Auto-generated TypeScript interface
export interface User {
    id: number;
    email: string;
    name: string;
}

// Auto-generated validation
export const validateUser = (user: User): ValidationResult => {
    // Consistent validation rules from metadata
};

Service Integration

Ensure consistent data models between services and external systems.

// Service A
UserDTO user = metaObjectService.convert(userEntity, UserDTO.class);

// Service B - automatically compatible
UserResponse response = externalService.createUser(user);

// Same metadata ensures compatibility

Migration Path

How to adopt MetaObjects in existing projects

From Traditional Development

Gradual adoption strategy for existing codebases:

  1. Define existing models as metadata
  2. Generate interfaces alongside existing code
  3. Gradually adopt runtime features
  4. Full metadata-driven architecture

From Other Frameworks

Integration strategies for popular frameworks:

  • Import existing schemas (JPA, JSON Schema)
  • Map to MetaObjects format
  • Generate compatibility layers
  • Incremental migration

External Resources

Additional documentation and examples

📖 GitHub Repository

Complete source code, examples, and issue tracking

View on GitHub

📝 API Documentation

Comprehensive JavaDoc documentation for all classes and interfaces

Browse API Docs

💡 Examples Repository

Sample projects demonstrating various MetaObjects patterns

View Examples

🗣️ Community Support

Get help from the community and contribute to the project

Join Community