Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6046791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:16:48+00:00 2026-05-23T07:16:48+00:00

I have an annotation, defined as so: public @interface RestletResourceVariable { String name(); }

  • 0

I have an annotation, defined as so:

public @interface RestletResourceVariable {
    String name(); 
}

I have a restlet ServerResource defined as so:

public class QuestionResource extends ServerResource {
    static Logger logger = LoggerFactory.getLogger(QuestionResource.class);

    @RestletResourceVariable(name="questionId")
    public String questionId; 

    @Get("json")
    public JsonRepresentation doGet() {
        logger.info("QuestionResource::doGet()");

        return new JsonRepresentation("{ nil };");
    }

    @Post
    public Representation doPost(Representation entity) throws Exception {
        logger.info("QuestionResource::doPost:" + entity.getText());
        return null;
    }
}

Here is my aspect:

public aspect RestletResourceVariableAspect { 
    static Logger logger = LoggerFactory.getLogger(RestletResourceVariableAspect.class); 

    pointcut RESTMethods() :
        execution( @org.restlet.resource.Delete * packagename..*(..) ) ||
        execution( @org.restlet.resource.Get    * packagename..*(..) ) || 
        execution( @org.restlet.resource.Post   * packagename..*(..) ) || 
        execution( @org.restlet.resource.Put    * packagename..*(..) ) 
        ;

    before(): RESTMethods() {
        Signature sig = thisJoinPoint.getSignature();

        Object target = thisJoinPoint.getTarget();
        Class<?> c = target.getClass();
        Class<?> cdecl = sig.getDeclaringType(); 

        logger.info("Class name: {} cdecl {}", c.getName(), cdecl.getName());
        logger.info("Sig: {} in class {}", sig.getName(),sig.getDeclaringType().getName());
        Field[] fields = cdecl.getDeclaredFields() ;
        for ( Field field : fields ) {
            logger.info("Field name: {}", field.getName());
            Annotation[] annotations = field.getDeclaredAnnotations();
            logger.info("Annotations {} length {}", annotations, Integer.toString(annotations.length));
            for(Annotation annotation : annotations){

                if(annotation instanceof RestletResourceVariable){
                    RestletResourceVariable myAnnotation = (RestletResourceVariable) annotation;
                    System.out.println("name: " + myAnnotation.name());
                }
            }

        }
    }
}

I get output like so:

16:22:11.656 [24864323@qtp-6011238-0] INFO  RestletResourceVariableAspect - Class name: QuestionResource cdecl QuestionResource
16:22:11.656 [24864323@qtp-6011238-0] INFO  RestletResourceVariableAspect - Sig: doGet in class QuestionResource
16:22:11.656 [24864323@qtp-6011238-0] INFO  RestletResourceVariableAspect - Field name: logger
16:22:11.656 [24864323@qtp-6011238-0] INFO  RestletResourceVariableAspect - Annotations [] length 0
16:22:11.656 [24864323@qtp-6011238-0] INFO  RestletResourceVariableAspect - Field name: questionId
16:22:11.656 [24864323@qtp-6011238-0] INFO  RestletResourceVariableAspect - Annotations [] length 0
16:22:11.656 [24864323@qtp-6011238-0] INFO  RestletResourceVariableAspect - Field name: ajc$tjp_0
16:22:11.656 [24864323@qtp-6011238-0] INFO  RestletResourceVariableAspect - Annotations [] length 0
16:22:11.656 [24864323@qtp-6011238-0] INFO  RestletResourceVariableAspect - Field name: ajc$tjp_1
16:22:11.656 [24864323@qtp-6011238-0] INFO  RestletResourceVariableAspect - Annotations [] length 0
16:22:11.656 [24864323@qtp-6011238-0] INFO  QuestionResource - QuestionResource::doGet()

Any guidance on what I’m doing wrong? I want to find the fields marked with the annotation so that I can populate them on request.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:16:49+00:00Added an answer on May 23, 2026 at 7:16 am

    Make sure you add @Retention(RetentionPolicy.RUNTIME) to the annotation definition like this:

    @Retention(RetentionPolicy.RUNTIME) 
    @Target ({ElementType.FIELD, ElementType.METHOD })
    @Inherited
    public @interface RestletResourceVariable {
        String name(); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following java class with the JAXB @XMLRootElement annotation @XmlRootElement(name=ClientData) public class
We have this JAXB annotation: @XmlElement(name = Strategy, required = true) protected List<Strategy> strategy;
I have written a small class, which reads out annotation from methods. Now I
In my project, I have defined the an annotation similar to the following: (Omitting
I have a newly defined annotation that is targeted at methods. Is there a
If a class defined an annotation, is it somehow possible to force its subclass
i'm experimenting with seam interceptors. I i have a custom annotation defined as: @Target(TYPE)
with spring 2.5, i have a class StockDwr StockDwr it's a bean name stock
I have an own annotation processor (let's call it MyProcessor) and a project (let's
I have written a java annotation that looks like this: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) // can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.