I am building a Dropwizard application where I want to easily map results from a MySQL database to java objects. I have seen this done before with an Object mapper, so I know it can be done, but unfortunately I can't remember where or how.
I created Immutable classes and I'd like to map the values to them. Here is an example Immutable:
@Value.Immutable
public interface Task {
int getTaskId();
int getCreatorId();
String getTitle();
String getDescription();
int getCreatedAt();
}
This is my DAO so far:
public interface TasksDAO {
@SqlQuery("select task_id, title, description, creator_id, created_at from tasks")
Set<ImmutableTask> getAllTasks();
@SqlQuery("select task_id, title, description, creator_id, created_at from tasks where id = :id")
ImmutableTask getTaskById(@Bind("id") int id);
}
It works with simpler data types like String
or int
.