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 8072299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:58:47+00:00 2026-06-05T13:58:47+00:00

I want to write my own validator and code generator for my beans. I

  • 0

I want to write my own validator and code generator for my beans. I define annotations and annotate my fields with them. When I validate them:

public boolean validate(Object obj) {
    Class clazz = obj.getClass();
    for (Field field : clazz.getDeclaredFields()) {
        for (Annotation annotation : field.getAnnotations()) {
            ...//What to do here
        }
    }
    return false;
}

i.e. my annotation is @NotEmpty

Should I go like if else if else ... or is there any other short way for it(and what to use to compare is that the annotation that I look i.e. @NotNull -> with annotation.equals(“NotNull”))? I mean how it can be implemented. On the other hand project Lombok has an annotation like that:

@Getter @Setter

How to generate getter and setters dynamically (or before compiling) for my classes(I want to implement it just with Java without any other libraries)?

  • 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-06-05T13:58:48+00:00Added an answer on June 5, 2026 at 1:58 pm

    I think you’d better search for the annotations you need rather that looping through all annotations. You can see if a annotation is present like this:

    field.isAnnotationPresent(NotEmpty.class)
    

    And to get the annotation and check it’s elements you can use:

    Annotation notEmpty = field.getAnnotation(NotEmpty.class)
    

    To modify your classes at runtime I think this is what you’re looking for. Here you can find a tutorial for ASM.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write my own __repr__ for some class that I define. I
Hello I want write my own desktop sharing application in Java. The application should
I want to write a browser-chat and write an own server in c++, because
I have created blank Asp.Net-MVC 3 web application and want to write my own
How to write a getter that can not be deleted? I want to own
I want write a little code analyzer which parses nested structures and translates into
I want to write an NSOutputStream to a server with apple's sample code: NSURL
I am embarking on some learning and I want to write my own syntax
I've install subversion, and want to write my own script to automate the web
I have a USB Joystick, and I want to write my own HID driver

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.