Lazyval: Compile-Time Code Generator for Domain Primimtives in Java or Kotlin

What is Lazyval / Motivation

Lazyval is a Java annotation processor & Kotlin symbol processor generating boilerplate code, often needed when modeling "Domain Primitives", which are simple, domain-specific wrapper types around primitives. The initial idea was inspired by Scalas Anyval; even though this works completely differently, it allows you to easily define a wrapper-type which captures the domain’s intent.

the term "Domain Primitive" was taken from the book Secure by Design.

Unfortunately, the ecosystem usually requires additional work when modeling custom types, which is often seen as too much of a burden.

As an example, take a regular project (Quarkus, Spring Boot) with Mapstruct and JPA. For each custom domain primitive, it is necessary to provide a JPA AttributeConverter to read/write to the Database, as well as a Mapstruct Mapper definition to wrap/unpack the type.

Lazyval will, depending on your classpath, generate:

  • a single Mapstruct-Mapper interface with mappings for all defined domain primitives

  • a JPA-AttributeConverter for each domain primitive

for custom generators, see Lazyvals SPI.
In a possible future where Java value-types are released and fully supported by the ecosystem (meaning you can use a value-type in an JPA entity without hassle), this project is probably not needed anymore.

Configuration Options

Property Description

lazyval.jpa.generatedPackage

Specifies the package where the AttributeConverter classes are generated to.

lazyval.mapstruct.generatedPackage

Specifies the package where the LazyvalMapper interface is generated to.

lazyval.disabledGenerators

Comma separated List of Generator-IDs which should not generate output despite being found on the classpath. Active Generator-IDs are printed to the console during compilation.

lazyval.values

Comma separated List with FQNs for classes which are not part of the current compilation-unit, but found on the classpath. See also Multi-Module Support.

License

This project is licensed under the [Apache License 2.0](LICENSE). You are free to use, modify, and distribute it under the terms of that license.

Cyber Resilience Act (CRA) Notice

Important Notice regarding the EU Cyber Resilience Act (CRA): This project is a developer tool and does not constitute a "product with digital elements" as defined under the CRA. It is not executed in production environments, nor does it process data during runtime.

The responsibility for the security, compliance, and correctness of the generated code lies entirely with the user. If the generated clients are used in safety-critical or regulated domains, users must perform their own security and compliance assessments.

Disclaimer of Liability

This project provides templates and helper scripts on an "as-is" basis, without any warranties.

The maintainers do not accept any liability for:

  • the security or correctness of generated code,

  • suitability for use in any specific technical or regulatory context.

Use of this project is at your own risk. Always validate generated code in accordance with your organization’s quality and security standards.