Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34659

Problem with validation

From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.java.programmer
Subject Problem with validation
Date 2016-06-16 08:08 +0200
Organization Decebal Computing
Message-ID <8760t97jjm.fsf@Equus.decebal.nl> (permalink)

Show all headers | View raw


We have a strange problem with validation. We defined the following
annotation:
    @Documented
    @Constraint(validatedBy = {})
    @Target({ FIELD })
    @Retention(RUNTIME)
    @ReportAsSingleViolation
    @NotNull
    @Size(min = 1)
    public @interface NotEmpty {
        // default
        final static String errorMessage = "Field is not allowed to be empty";

        Class<?>[] groups() default {};

        String message() default errorMessage;

        Class<? extends Payload>[] payload() default {};
    }

We have this annotation defined on 8 fields, like:
    @NotEmpty(message = "ZIP-code is not allowed to be empty")

Only one field (the one with the ZIP-code) is empty, but when we call
persist we get a validation exception of five of them. When we print
the name of the field, the message and the invalid value, we see it is
the NotEmpty annotation that fired and that except for ZIP-code the
fields are filled. ZIP-code contains the empty string.

Also when we fill ZIP-code the persist does not fire with an
validation exception.

What could be the reason we get a validation exception for four fields
we should not get one for?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Problem with validation Cecil Westerhof <Cecil@decebal.nl> - 2016-06-16 08:08 +0200
  Re: Problem with validation Lew <lewbloch@gmail.com> - 2016-06-16 14:25 -0700

csiph-web