Dynamically add fields to an object using annotations (Java/Groovy) -
i'm trying use java annotations able add specific fields object.
the need following : have class processes configuration files keys associated values form key=value.
the problem want able let user defining himself required fields which, if not present, throws exception.
the easiest solution pass these fields constructor in string[] but, want user able use these required fields properties of class, he's able write in code :
@requiredfields( field1, field2, field3) myclass myobject = new myclass(string filepath); string value = myobject.field1;
and field field1 completion proposal ?
i'm developping in groovy, if not possible in standard java, in groovy ?
thanks !
what factory method validation? like:
myclass = myclassfactory.create("arg1", "arg2")
or, maps on groovy:
def = myclassfactory.create arg1: "foo", arg2: "bar"
and factory checks properties file.
if want annotation, maybe type annotations on jdk 8 option.
on groovy, can try local ast, seems overengineered solution me, or gcontracts programming contract.
you combine factory gcontracts @ensure
resulting object contains fields according properties file.
Comments
Post a Comment