1

It seems that the java code generator framework CodeModel is not capable of creating annotations which only contain an enum value without a name - unfortunately a very common pattern (which JPA uses, for example):

  @Temporal(TemporalType.TIMESTAMP)
  private Date createDate;

The API documentation only states "TODO How to add enums to the annotations"

Question:
Is there any way of working around this limitation?

MRalwasser
  • 15,605
  • 15
  • 101
  • 147

2 Answers2

1

I'd say that comment is out of date. There is a method param(String name, Enum<?> value) on JAnnotationUse which works fine.

Edit: The code would look like the following:

field.annotate(Temporal.class).param("value", TemporalType.TIMESTAMP)

Please note that

@Temporal(TemporalType.TIMESTAMP)

Is just a short for of writing

@Temporal(value=TemporalType.TIMESTAMP)

This short form can be used when the annotation only contains a single parameter.

Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118
1

Annotation parameters "without a name" are actually just a shorthand for a default parameter named "value", so these are equivalent:

@Temporal(TemporalType.TIMESTAMP)

@Temporal(value=TemporalType.TIMESTAMP)
Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720