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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:49:24+00:00 2026-05-24T23:49:24+00:00

How can I go about overriding the validation on the email for the AuthorizedUser

  • 0

How can I go about overriding the validation on the email for the AuthorizedUser in the following situation:

public class Account {
    @Length(min = 1, max = 100, 
            message = "'Email' must be between 1 and 100 characters in length.")
    @NotNull(message = "'Email' must not be empty.")
    protected String email;

    @Length(min = 1, max = 50,
            message = "'Name' must be between 1 and 50 characters in length.")
    private String name;
}

public class AuthorizedUser extends Account {
    @Length(min = 1, max = 40,
            message = "'Field' must be between 1 and 50 characters in length.")
    private String field;
}

I know I could ‘hack’ the solution by overriding the email address in the setter on the AuthorizedUser by doing the following:

@Override
public void setEmail(String email) {
   this.email = email;
   super.setEmail(" ");
}

It just feels dirty… Is this possible to be overridden without writing a custom validator?

I tried moving the @Valid to the setter in the super class, and leaving it off in the overridden field, but I still receive the message from the super class about it being empty. Is there a lazier way to do this?

  • 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-24T23:49:25+00:00Added an answer on May 24, 2026 at 11:49 pm

    Since constraints are aggregated through inheritance, the best solution may be to change your inheritance hierarchy to something like this:

    public class BasicAccount {
      protected String email;
    
      @Length(min = 1, max = 50,
              message = "'Name' must be between 1 and 50 characters in length.")
      private String name;
    }
    
    public class EmailValidatedAccount extends BasicAccount {
      @Length(min = 1, max = 100, 
              message = "'Email' must be between 1 and 100 characters in length.")
      @NotNull(message = "'Email' must not be empty.")
      @Override
      public String getEmail() {
        return email;
      }
    }
    
    public class AuthorizedUser extends BasicAccount {
      @Length(min = 1, max = 40,
              message = "'Field' must be between 1 and 50 characters in length.")
      private String field;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've heard about how base classes and method overriding can be combined to eliminate
This question is about overriding a virtual method in a derived class with a
As a relative newbie I try to read as much as I can about
You can read about the 64-bit calling convention here . x64 functions are supposed
can anyone point to a site or describe how I can go about designing
Does anyone know how I can go about hiding the tab selectors for the
I am wondering how I can go about stopping a dialog from opening if
It seems that all of the documentation I can find about OpenGL-ES says something
How can I go about generating a Friendly URL in C#? Currently I simple
How can I go about storing a vb.net user defined object in a sql

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.