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

  • Home
  • SEARCH
  • 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 8484745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:27:36+00:00 2026-06-10T20:27:36+00:00

I have specified a custom annotation for use in Java bean-validation. I use the

  • 0

I have specified a custom annotation for use in Java bean-validation. I use the same annotation class for all of my fields and pass a string parameter with the name of the field, like this:

@CustomConstraint(value="name")
private String name;
@CustomConstraint(value="address1")
private String addressLine1;

My constraint validator maintains a HashMap that maps String keys (name of field) to an Interface for my validation classes. I statically initialize this map by pairing particular field names with concrete subclasses of the interface that will be used to validate the field, like this:

private static final Map<String, CustomValidatorClass> fieldMapper; 

static {
    Map<String, CustomValidatorClass> map = new HashMap<String, CustomValidatorClass>();
    map.put("name", new NameValidator());
    map.put("address1", new Address1Validator());
    fieldMapper = Collections.unmodifiableMap(map);
}

My concern is that this initialization process could be quite expensive (I have dozens of fields), and that it may be initialized for every single field which I am validating. I am hoping that there is some way to specify that the annotation should be initialized once and reused, or that this is the default behavior.

EDIT: I am using JSF 2.0 along with bean-validation, so I am not directly reading or calling these annotations. That is handled by the framework, which is why I could not determine exactly how it was operating.

  • 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-10T20:27:36+00:00Added an answer on June 10, 2026 at 8:27 pm

    I did some testing and it seems that the static initialization I am doing on my map is only being called the first time I attempt to validate a field. This means that the Annotation is not being initialized repeatedly and is instead being reused for each field. My worry about overhead in my large initialization is now addressed.

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

Sidebar

Related Questions

Say I have a class with a few fields all marked with a custom
I have an ASP.NET page and some custom class that fetches a specified webpage
I have a WCF service for which I have specified custom binding/readerQuotas settings. However,
previously i had custom tableviewcell and was loading from Nib.in that i have specified
I have a custom closed-hashset/open-addressing (i.e. no linked lists) class. It's very specific to
I am trying to pull excerpts and custom fields from specific posts, I have
I need my application run in multiple screen resolutions. Currently I have specified all
I would like use a panel whose children have coordinates specified as percentage of
I have my custom attr.xml document in which I specified declare-styleable : <?xml version=1.0
I have created custom result class to serialize json data to xml. I want

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.