Immutables

Java annotation processors to generate simple, safe and consistent value objects. Do not repeat yourself, try Immutables, the most comprehensive tool in this field!

Get started! Read guide... v2.10.1
import org.immutables.value.Value;
// Define abstract value type
@Value.Immutable
public interface ValueObject {
  String name();
  List<Integer> counts();
  Optional<String> description();
}
// Use generated immutable implementation
ValueObject valueObject =
    ImmutableValueObject.builder()
        .name("My value")
        .addCounts(1)
        .addCounts(2)
        .build();
// Or you can configure different @Value.Style
@Value.Immutable
abstract class AbstractItem {
  abstract String getName();
  abstract Set<String> getTags();
  abstract Optional<String> getDescription();
}
// Use generated value object
Item namelessItem = Item.builder()
    .setName("Nameless")
    .addTags("important", "relevant")
    .setDescription("Description provided")
    .build();

Item namedValue = namelessItem.withName("Named");

Values and Builders

With Immutables you can generate state of the art immutable objects and builders. Type-safe, null-safe and thread-safe, with no boilerplate. Generate builders for immutable objects and even plain static factory methods.

Easy to use

Just add jar to classpath and use. No required runtime dependencies! Guava is supported, but not required. Works out-of-the box with build tools, integrates into IDEs. Get started!

Feature packed

Lazy, derived and optional attributes. Comprehensive support for collections as attributes, including Guava collections. Generic parameters. Copy with structural sharing. Singleton and interned instances… and more!

Clean code

Immutables has much higher standards for code readability than other generators. Generated APIs are carefully tuned for the best power-to-weight ratio. No ugly named identifiers. Implementation code is clear, efficient, and have corresponding javadocs. Take a look

Flexible

Adapt Immutables to your code conventions and tastes. Customize get, set, with or whatever prefixes. Describe styles as reusable meta-annotations. Generate as much or as little as you need, expose or hide generated classes. Go rogue with Encodings to implement custom attribute types!

JSON

Immutables are serialization ready, including JSON and its binary forms. Jackson and Gson libraries are supported. Gson is integrated using generated TypeAdapters which use no reflection. JSON guide. MongoDB repositories also included.

Criteria

Generate typesafe query and repository DSL to access different datasources.


Classes, Interfaces and Annotations Builders Constuctor methods With-copy methods equals, toString, hashCode methods Default attributes Derived attributes Lazy attributes Optional attributes Array, List, Set and Map attributes Singleton values Instance interning hashCode precomputing JSON serialization JAX-RS integration MongoDB integration Query DSL