I have this enum :
public enum DocumentTypes {
PDF("PDF Document"), JPG("Image files (JPG)"), DOC("Microsoft Word documents");
private final String displayName;
DocumentTypes(final String display) {
this.displayName = display;
}
@Override
public String toString() {
return this.displayName;
}
}
And a model like this :
@Entity
@Table(name = "documents")
public class Document extends Model {
@Id
public Long id;
@Constraints.Required
@Formats.NonEmpty
@Enumerated(EnumType.STRING)
@Column(length=20, nullable=false)
public DocumentTypes type;
@Constraints.Required
@Formats.NonEmpty
@Column(nullable=false)
public String document;
}
I match the enum using this in my controller :
DynamicForm form = form().bindFromRequest();
// ...
Document doc = new Document();
doc.type = DocumentTypes.valueOf(form.field("type").value());
doc.save();
The problem is that in database, it's stored as "Microsoft Word documents", but I would prefer to store it as DOC.
How can I do that?