This seems like it would be a really common thing to need in just about any Java project. And yet I am unable to find anything that serves this purpose.
I used to use a web framework called Stripes Framework, that had annotation driven validators and automatic formatting via their validator API.
Example:
@Validate(maxlength = ModelConstants.NAME_MAX_LENGTH, converter = CapitializeFullyTypeConverter.class)
private String name;
@Validate(maxlength = ModelConstants.NAME_MAX_LENGTH, converter = EmailTypeConverter.class)
private String email;
Those fields would be defined on your controller action bean, and all user input would automatically be validated and formatted according to the specified rules.
If someone would enter their email address as: "TEST@TEST.COM" Then it would automatically be formatted to: "test@test.com"
I would like to find something like this for automatically formatting data within DTOs.
If nothing like this is available, what is the usual way of handling this? Surely everyone is not writing custom formatting functions for each getter within the DTO?