java - Reading values assigned to annotated field -
i new java 8 , spring mvc . have java bean pojo setter , getter. spring web service using reflection maps request parameters pojo. want input validation using annotation. have requirement need read values of annotated field , check atleast 1 value provided. wrote sample code.... not sure how values assigned field. please share sample code if have:
public boolean isvalid(string object, constraintvalidatorcontext constraintcontext) { boolean canproceed = false; for(field field : documentsearchrequest_global.class.getdeclaredfields()) { if (field.isannotationpresent(validdocumentmodifieddate.class)) { string name = field.getname(); //iam able name of field system.out.println("1.name : "+ name); system.out.println("2. "+field.gettype().getname()); } } // method[] method = documentsearchrequest_global.class.getdeclaredmethods(); (method method :documentsearchrequest_global.class.getdeclaredmethods() ) { system.out.println(method.getname() ); //able name of getter , setter methods in pojo //can u suggest how read value of particular field.. either //getting value method??? ... }
you can values calling method.invoke(object, object...)
first parameter class instance on method executed , second variable arguments arguments of method. in case it'll null or empty. here simple code snippet object value = method.invoke(documentsearchrequest_global_instance);
Comments
Post a Comment