What’s New in tinystruct 1.7.34
This document highlights the new features, improvements, and changes introduced in tinystruct version 1.7.34.
See also: What’s New in 1.7.32 for the previous release featuring UUID/JSONB support and the FieldInfo refactor.
Highlights of 1.7.34
- Enum-Collection Argument Support:
@Actionmethods can now acceptList<EnumType>parameters — comma-separated strings are automatically converted to enum collections. - Annotation-Driven ORM Mapping: New
@Table,@Id, and@Columnannotations enable declarative, code-first POJO mapping without relying on XML configuration. - Opt-In Table Auto-Creation: The ORM layer can now automatically create tables on first use when the
autoCreateflag is set on a mapped entity. idAttribute Renamed: The ambiguousidattribute inFieldInfohas been split into the more explicitautoIncrementandautoGeneratedfields for clarity.- Generator Annotation Mode: All POJO generators support a new annotation output mode, emitting
@Table/@Id/@Columnannotations directly in generated source files. - Fat JAR Removed: The default fat JAR artifact has been dropped in favour of a leaner, dependency-managed distribution.
Major New Features & Enhancements
1. Enum-Collection Argument Conversion
@Action methods that declare a List<E extends Enum<E>> parameter now work seamlessly from both CLI and HTTP contexts. The framework automatically splits a comma-separated string value and converts each token to the target enum constant.
Example
public enum Role { ADMIN, USER, GUEST }
@Action(value = "set-roles", description = "Assign roles to a user",
arguments = { @Argument(key = "roles", description = "Comma-separated roles") })
public String setRoles(List<Role> roles) {
return "Assigned: " + roles;
}
# CLI usage
bin/dispatcher set-roles --roles ADMIN,USER
# HTTP usage
GET /set-roles?roles=ADMIN,USER
Both invocations produce Assigned: [ADMIN, USER].
2. Annotation-Driven ORM Mapping (@Table, @Id, @Column)
Three new annotations make it possible to define the full ORM mapping directly on your POJO class, mirroring the popular JPA approach while staying within the tinystruct ecosystem.
| Annotation | Target | Purpose |
|---|---|---|
@Table |
Class | Maps the class to a database table |
@Id |
Field | Marks the primary key field |
@Column |
Field | Maps a field to a specific column name and type |
Example
import org.tinystruct.data.component.Table;
import org.tinystruct.data.component.Id;
import org.tinystruct.data.component.Column;
@Table(name = "users")
public class User extends AbstractData {
@Id
@Column(name = "id", type = "INT", autoIncrement = true)
private int id;
@Column(name = "username", type = "VARCHAR", length = 100)
private String username;
@Column(name = "email", type = "VARCHAR", length = 255)
private String email;
// getters and setters...
}
The XML mapping file is now optional when annotations are present.
3. Opt-In Table Auto-Creation
When autoCreate = true is set on the @Table annotation, tinystruct will inspect the mapped columns and issue a CREATE TABLE IF NOT EXISTS DDL statement the first time the entity is accessed. This removes manual schema setup during development and testing.
@Table(name = "sessions", autoCreate = true)
public class Session extends AbstractData {
@Id
@Column(name = "id", type = "VARCHAR", length = 64)
private String id;
@Column(name = "user_id", type = "INT")
private int userId;
@Column(name = "expires_at", type = "TIMESTAMP")
private java.time.LocalDateTime expiresAt;
}
Note: Auto-creation is opt-in and disabled by default. It is recommended only for development or test environments.
4. FieldInfo Attribute Renaming
To improve code clarity, the previously ambiguous id boolean attribute on FieldInfo has been replaced by two distinct fields:
| Old Attribute | New Attribute | Meaning |
|---|---|---|
id = true (auto-increment) |
autoIncrement = true |
Column is a DB-managed auto-increment PK |
id = true (UUID) |
autoGenerated = true |
Value is application-generated (e.g., UUID) |
This change aligns FieldInfo semantics with the new @Id annotation and eliminates the overloaded meaning of the old id flag.
5. Generator Annotation Mode
All five POJO generators now support an annotation output mode. When enabled, the generated Java source includes @Table, @Id, and @Column annotations, making the output immediately usable with the new annotation-driven ORM layer.
# Generate a POJO with annotations from a MySQL table
bin/dispatcher generate --table users --driver mysql --annotations
Migration Guide
Updating to 1.7.34
Update your pom.xml dependency:
<dependency>
<groupId>org.tinystruct</groupId>
<artifactId>tinystruct</artifactId>
<version>1.7.34</version>
</dependency>
FieldInfo Migration
If you set the id attribute directly on a FieldInfo instance, update to the new named fields:
// Before (≤ 1.7.32)
fieldInfo.setAutoIncrement(true); // was: fieldInfo.put("id", true)
// After (1.7.34)
fieldInfo.setAutoIncrement(true); // auto-increment primary key
fieldInfo.setAutoGenerated(true); // UUID / app-generated value
Code accessing FieldInfo through the standard append/set/get compatibility facade remains source-compatible without changes.
Community and Resources
- GitHub Repository: https://github.com/tinystruct/tinystruct
- Official Documentation: https://tinystruct.org
- Examples: https://github.com/tinystruct/tinystruct-examples
- Project Archetype: https://github.com/tinystruct/tinystruct-archetype