Stop writing Java toString() methods.
JWeaver is a zero-configuration object renderer for debugging, logging and testing.
Instead of manually maintaining toString(), configuring serializers, or fighting unreadable logs:
System.out.println(JWeaver.weave(order));Get readable output immediately.
Given this objects:
class Order {
Customer customer;
List<Item> items;
Payment payment;
}
class Customer {
String name;
Address address;
}No toString() anywhere. System.out.println(order) gives you:
Order@6b95977
JWeaver.weave(order) renders a compact, single-line view with quoted strings and element counts:
Order[customer=Customer[name="John", address=Address[street="123 Main St", city="Anytown"]], items=List[1][Item[name="Widget"]], payment=Payment.CASH]
For a hierarchical view, use Mode.TREE:
System.out.println(JWeaver.weave(order, Mode.TREE));Order
|-- customer=Customer
| |-- name="John"
| `-- address=Address
| |-- street="123 Main St"
| `-- city="Anytown"
|-- items=List[1]
| `-- [0] Item
| `-- name="Widget"
`-- payment=Payment.CASH
No annotations.
No configuration.
No handwritten toString().
✓ Zero configuration
✓ Cycle-safe object traversal
✓ Human-readable object trees
✓ Logging friendly
✓ Works with existing objects immediately
✓ Replace boilerplate toString() methods
JWeaver requires Java 21 or newer. It is built with --release 21 and tested
against Java 21 and 25 in CI.
Maven:
<dependency>
<groupId>com.robinloom</groupId>
<artifactId>jweaver-api</artifactId>
<version>4.2</version>
</dependency>For the SLF4J logging integration, add:
<dependency>
<groupId>com.robinloom</groupId>
<artifactId>jweaver-logging</artifactId>
<version>4.2</version>
</dependency>User user = createUser();
String output = JWeaver.weave(user);
System.out.println(output);You can call JWeaver.weave(...) yourself:
LOGGER.info("Authenticated user: {}", JWeaver.weave(user));Or use the SLF4J integration from jweaver-logging. Its LoggerFactory returns a regular SLF4J Logger that renders object arguments with JWeaver automatically:
import com.robinloom.jweaver.logging.LoggerFactory;
import org.slf4j.Logger;
private static final Logger LOGGER = LoggerFactory.getLogger(UserService.class);
LOGGER.info("Authenticated user: {}", user);- Strings and exceptions are passed through unchanged, everything else is woven.
- Arguments are only rendered if the log level is enabled.
- The default is
Mode.INLINE. Pass a mode for other output:LoggerFactory.getLogger(UserService.class, Mode.TREE). - It wraps whatever SLF4J backend you already use (Logback, Log4j 2, ...).
To keep the output readable and bounded, JWeaver cuts off large values:
| What | Limit | Output |
|---|---|---|
| Nested string | 1000 characters | "abc..." (5000 chars) |
| Items per collection, array or map | 10 | N more |
| Nesting depth | 10 | Node[...] |
| Objects and collections per weave call | 1000 | Node[...] |
Fields that look sensitive (such as password or token) are masked automatically. For guaranteed masking, annotate a field with @WeaveRedact:
class Credentials {
String username = "robin";
@WeaveRedact String note = "hello";
String password = "hunter2";
}Credentials[username="robin", note=***, password=***]
Name-based detection is a best-effort heuristic. Use @WeaveRedact for anything that must never appear in output.
Handwritten / IDE-generated toString() |
Lombok @ToString |
JWeaver | |
|---|---|---|---|
| Maintenance | Update by hand when fields change | Annotation on every class | None |
| Works on objects you don't own | No | No | Yes |
| Cycle-safe | Only if you handle it | Needs @ToString.Exclude |
Built in |
| Sensitive data masking | Manual | Manual (@ToString.Exclude) |
Automatic + @WeaveRedact |
- Object tree rendering
- Reflection-based traversal
- Cycle detection
- Collection rendering
- Configurable rendering strategies
- Sensitive data redaction
- Custom renderers
- Logging integration
Use JWeaver when:
- debugging complex objects
- replacing handwritten
toString() - improving logs
- inspecting DTOs
- writing diagnostics
- creating readable test output
Do not use JWeaver when:
- you need serialization
- you need machine-readable output
- you need persistence formats
JWeaver is modular internally to separate rendering, reflection, logging and extension APIs while keeping usage simple.