Giter Site home page Giter Site logo

validation's Introduction

Jakarta Validation API

This repository contains the Java Jakarta Validation 3.0 API.

Jakarta Validation defines a metadata model and API for JavaBean and method validation.

You can learn more about it here:

System requirements

JDK 8.

Licensing

The Jakarta Validation API is provided and distributed under the Apache Software License 2.0. Refer to license.txt for more information.

Build from Source

You can build the Jakarta Validation API from source by cloning the git repository https://github.com/jakartaee/validation You will also need a JDK 8 and Maven 3 (>= 3.0.3). With these prerequisites in place you can compile the source via:

mvn clean install

Contribute

Want to join us? You can find all the relevant information about contributing to Jakarta Validation on the website.

Continuous Integration

The official Continuous Integration service for the project is hosted on ci.eclipse.org.

Publishing the Schemas

The schema files should be published to the https://github.com/jakartaee/jakarta.ee website repository by following the procedure described at https://eclipse-ee4j.github.io/jakartaee-platform/publish-xml-schemas. The location for the schema files in the repository is the static/xml/ns/validation directory.

validation's People

Contributors

akmalick avatar davided avatar dependabot[bot] avatar emmanuelbernard avatar gsmet avatar gunnarmorling avatar hendrikebbers avatar hferentschik avatar hibernate-ci avatar kabir avatar kasabuta4 avatar mswatosh avatar starksm64 avatar yrodiere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

validation's Issues

Be able to compose Pattern list with OR expression

Nowadays @pattern validator is able to match a list of patterns. But the validation passes if all of pattern matches.
It could be helpful having a @Pattern.List configuration for tell the need to pass all (AND composition) or at least one (OR composition)

Prepare Jakarta Bean Validation for Jakarta EE 8 Release

Instructions

  • Update text files
  • Generate "boilerplate" specification project
  • Make a staging release of the API from the master branch
  • Make a release from the spec from the master branch
  • Make a staging release of the TCK from the 2.0 branch and push it on downloads.eclipse.org
  • Generate Stand-alone TCK test results
  • Create a PR to jakartaee/specifications repository
  • Update the Jakarta EE API jar by submitting a PR to the jakartaee-api project

Details are here:

Add validation configuration/mapping XSDs for 3.1 version

https://github.com/jakartaee/validation/tree/main/src/main/xsd does not include XSDs for Jakarta Validation 3.1. While there were no changes in this area, it would be good to have the XSDs there, even if just for the 3.1 in the XMLs:

<validation-config
    xmlns="https://jakarta.ee/xml/ns/validation/configuration"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="https://jakarta.ee/xml/ns/validation/configuration https://jakarta.ee/xml/ns/validation/validation-configuration-3.1.xsd"
    version="3.1">

    <property name="smth">value</property>
</validation-config>

and if we do so, the XSDs should be available through https://jakarta.ee/xml/ns/validation/

Make adding constraints easier

Imho, adding custom constraints should be easier than it is now. It is cumbersome to define an annotation and an implementation class if you just want to compare some fields with each other.

why is something like this not possible ?

class Person {
   @Size(min=3)
   String lastname;
  
   @PastOrPresent
   LocalDate birthday:

   @Pattern(โ€œ\\d{8}โ€)
   String ssn;

   @Constraint
    boolean validate() {
       return ssn != null || (birthday != null && lastname != null);
    }
}

The validate method will also be invoked as part of validating this bean after its fields have been validated. And the method annotated with @constraint should always return a boolean.

This is much easier to use and everything you need from the bean is there.

Jakarta Validation 3.1 compatible implementation

Looking at https://jakarta.ee/specifications/bean-validation/3.1/ a compatible implementation is displayed as [Hibernate Validator 8.0.1.Final](https://hibernate.org/validator/releases/8.0/)

Hibernate Validator 8.0 series is a Jakarta Bean Validation 3.0-based implementation. While there weren't any updates to the Jakarta Validation API, and 8.0 would probably pass the TCK as it should also be more or less the same, the currently developed 9.0 series of Hibernate Validator is the one that targets the Jakarta Validation 3.1 API.

A 3.1-compatible version should be updated once the 9.0 series is published.

Copyright Notice in License is missing

For companies that use this library, it is important to understand who is the copyright holder.
In the license file that is attached, the copyright holder is not clearly stated but it is still kept as the template value.

It would be great if you could add the name(s) of the copyright holder such that the legal situation gets clarified properly.

Added uses statements to module-info.java

Currently, the beans validation API is failing at runtime for me when I attempt to use it with the Java Module System. The runtime complains that the beans validation module-info does not contain a "uses" clause.

To fix this, please add the following to module-info.java:

uses jakarta.validation.spi.BootstrapState;
uses jakarta.validation.spi.ConfigurationState;
uses jakarta.validation.spi.ValidationProvider;

I have tried this on my machine, and it works.

Thank you.

Validation 3.1 M1 Release

The Jakarta EE platform is looking for an M1 release from each spec by November 28th, we should look at what (if anything) we want to include in the M1. For open issues we have:

Even if we don't add anything for the M1, we still need to go through the release process. @VIGNESH-RAMALINGAM and I can help with the release, but we haven't been through one before, so I'm not sure what the steps are.

Incorrect metadata registered with maven repo

While writing a tool to check for updates to my dependencies, I noticed that the central maven repository has incorrect information about this package.

The information seen here is correct, with multiple versions available.
https://repo1.maven.org/maven2/jakarta/validation/jakarta.validation-api/

However, the actual file that most automatic tools would be parsing says that 2.0.1 is the ONLY version. It looks like the file has not been updated since the initial release in 2018

https://repo1.maven.org/maven2/jakarta/validation/jakarta.validation-api/maven-metadata.xml

<metadata>
  <groupId>jakarta.validation</groupId>
  <artifactId>jakarta.validation-api</artifactId>
  <versioning>
    <latest>2.0.1</latest>
    <release>2.0.1</release>
    <versions>
      <version>2.0.1</version>
    </versions>
    <lastUpdated>20181126155025</lastUpdated>
  </versioning>
</metadata>

Support the Valid annotation on parameterized types to an interface class

Please add this in Jakarta EE 11. It is needed by Jakarta Data.

When performing method validation on methods that came from an interface and you don't control the interface yourself, it is currently not possible to request cascading validation on the parameters and return value of the method. The proposal is to support annotating type parameter(s) with @Valid when inheriting from the interface in order to request that cascading validation be automatically performed during method validation for parameters and return values of the annotated type.

For example, Jakarta Data has a built-in interface CrudRepository, which defines a very commonly used save operation, which is where validation of constraints on the passed-in entity parameter is often desired. Jakarta Data repositories that the user defines inherit from this interface, for example,

@Repository
public interface School extends CrudRepository<Student, Integer> {
... // inherits save(Student) operation from CrudRepository
}

@Entity
public class Student {
   @Email
   public String email;
   @NotBlank
   public String name;
   @Id
   public int studentId;
}

The user who defines this class, would like to annotate the Student parameter with @Valid, as follows:

@Repository
public interface School extends CrudRepository<@Valid Student, Integer> {
... // inherits save(Student) operation from CrudRepository
}

which we would like to see cause the constraints of the Student class to be validated when a Student object is supplied to:

    school.save(student);

Mailing list discussion:
https://www.eclipse.org/lists/bean-validation-dev/msg00029.html

An error occurred while using ConvertGroup.List HV000124: Found multiple group conversions for source group

From the error message, it appears that I have multiple group conversions, but in reality, I only have one
I have a simple Spring Boot project

import jakarta.validation.Valid;
import jakarta.validation.groups.ConvertGroup;
import jakarta.validation.groups.Default;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

This is my JavaBean class

@ NotBlank and @ Size were set for field01 and field respectively, and groups were established

public class MyTestBean {

	@NotBlank(groups = {NotBlankCheck.class})
	private String field01;

	@Size(max = 3, min = 0 ,groups = {SizeCheck.class})
	private String field02;

	public String getField01() {
		return field01;
	}

	public void setField01(String field01) {
		this.field01 = field01;
	}

	public String getField02() {
		return field02;
	}

	public void setField02(String field02) {
		this.field02 = field02;
	}

}

This is my model, using @ Valid for testBean01 and testBean02
All types are MyTestBean
ConvertGroup has been set up, hoping to perform NotBlank check only on field01 for testBean01 and Size check only on field02 for testBean02

public class MyModel {
	
	interface Action01{
		
	}
	
	@Valid
	@ConvertGroup.List({
		@ConvertGroup(from=Default.class,to=NotBlankCheck.class)
	})
	private MyTestBean testBean01;

	@Valid
	@ConvertGroup.List({
		@ConvertGroup(from=Default.class,to=SizeCheck.class)
	})
	private MyTestBean testBean02;
	
	public MyTestBean getTestBean01() {
		return testBean01;
	}

	public void setTestBean01(MyTestBean testBean01) {
		this.testBean01 = testBean01;
	}

	public MyTestBean getTestBean02() {
		return testBean02;
	}

	public void setTestBean02(MyTestBean testBean02) {
		this.testBean02 = testBean02;
	}

}

This is my Controller

@Controller
@RequestMapping("/")
public class MyController {

	@ModelAttribute
	public MyModel setUpForm() {
		MyModel myModel = new MyModel();
		MyTestBean bean01 = new MyTestBean();
		bean01.setField01("");
		bean01.setField02("abcdef");
		MyTestBean bean02 = new MyTestBean();
		bean02.setField01("");
		bean02.setField02("abcdef");
		myModel.setTestBean01(bean01);
		myModel.setTestBean02(bean02);
		return myModel;
	}

	@GetMapping(value = "test")
	public String test(@Validated MyModel myModel, BindingResult result) {
		if (result.hasErrors()) {
			return "null";
		}
		return "success";
	}

}

But when I accessed the controller, an error occurred,Regardless of the situation, I will encounter this error when using @ ConvertGroup.List, even if I delete other @ ConvertGroups and only keep one

jakarta.validation.ConstraintDeclarationException: HV000124: Found multiple group conversions for source group jakarta.validation.groups.Default: com.example.validatedemo2.NotBlankCheck.
	at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getGroupConversions(AnnotationMetaDataProvider.java:567) ~[hibernate-validator-8.0.1.Final.jar:8.0.1.Final]
	at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getGroupConversions(AnnotationMetaDataProvider.java:547) ~[hibernate-validator-8.0.1.Final.jar:8.0.1.Final]

But when I don't use List, but instead use @ ConvertGroup, everything works fine..But I do need to use List

	@Valid
	@ConvertGroup(from=Default.class,to=NotBlankCheck.class)
	private MyTestBean testBean01;

	@Valid
	@ConvertGroup(from=Default.class,to=SizeCheck.class)
	private MyTestBean testBean02;

Is there a misunderstanding about my use of @ConvertGroup.List? Or does he have some problems with himself

validatedemo2.zip

Jakarta.validation API 3.0.1 is backward incompatible

The API contains OSGi header Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=9.0))", unlike the 3.0.0 API.

This requirement for JDK 9 is a backward-incompatible change that should not be introduced in a service release of the API.

Move this repo to https://github.com/jakartaee

In the steering committee we voted to moved all specification projects from eclipse-ee4j to jakartaee. As such this repo should move to in due time.

Moving is fairly automatic, and redirects will be automatically put in place from the current location here to the new location.

If someone can authorise the move (e.g. @gunnarmorling @MattGill98) I can take care of it if needed.

Extra info:

"We voted on it in 2019 and then in 2020 we added it explicitly to our 2021 plan and voted on that plan. I think we just need to start executing. I sent about 30 emails like the following in an attempt to add some shape to it and kick off the move in the spec projects.

From: https://www.eclipse.org/lists/jakarta.ee-spec/msg02073.html

Also note that many projects have indeed moved: https://github.com/jakartaee/

beanvalidation.org is no longer maintained

There is a website for "bean validation" out there: https://beanvalidation.org/

However:

  1. The news section hasn't been updated in years.
  2. The website doesn't mention Jakarta Validation 3.1 -- and is probably outdated in other areas.
  3. The website is hosted on Red Hat infrastructure, and maintained by the Hibernate team, with no involvement or control from the Eclipse foundation.
  4. Jakarta Validation already has a website: https://jakarta.ee/specifications/bean-validation/

I wouldn't be able to tell you who has ownership of the DNS records, but I can try to find out, and I suspect the Eclipse Foundation would want to own it.

What should we do with this website?

  1. Keep things as they are, with outdated information.
  2. Transfer ownership (push access) to people working on Jakarta Validation.
  3. Re-host it somewhere on Eclipse infrastructure, and keep it up to date.
  4. Re-host it somewhere on Eclipse infrastructure, for archive purposes, with some added banner to mention the content is obsolete.
  5. Completely lose the content and change the DNS to redirect to some other Eclipse website (https://jakarta.ee/specifications/bean-validation/ or this GitHub repo).
  6. Something else?

The Hibernate team can help with the transfer of hosting/ownership, but I don't think we will be able to keep the website up to date.

cc @starksm64

Provide access to unwrapped value for `ConstraintViolation` on container method argument or return value

For method validation on arguments or return values that are containers, it would be useful to have access to the unwrapped value. For lists, arrays, and maps it is possible to get the containerIndex or containerKey from the next Path.Node and use that to get the value, but there is nothing for Iterable and other containers.

ConstraintViolation exposes part of the object graph through rootBean and leafBean. Perhaps Path.Node could provide access to the unwrapped value associated with that part of the property path, but there may be other ways.

Publish the version 3.0.2

I'm trying to use the Bean Validation with the module system, and it requires the uses. It was already fixed, but I'd like to know when this fix will be published.
Currently, it is blocking me to use the module system correctly, so it would be great if the fix is published soonish.

Stuck thread due to WeakHashMap

Stuck threads at
(self-tuning)'" #262 daemon prio=1 os_prio=0 tid=0x00007f1480091000
nid=0x187a runnable [0x00007f1456863000]
java.lang.Thread.State: RUNNABLE
at java.util.WeakHashMap.get(WeakHashMap.java:403)
at
javax.validation.Validation$GetValidationProviderListAction.getCachedValidatio

nProviders(Validation.java:368)

  • locked <0x00000005f44e3e10> (a
    javax.validation.Validation$GetValidationProviderListAction)
    at
    javax.validation.Validation$GetValidationProviderListAction.run(Validation.jav

a:323)
at
javax.validation.Validation$GetValidationProviderListAction.getValidationProvi

derList(Validation.java:316)
at
javax.validation.Validation$DefaultValidationProviderResolver.getValidationPro

viders(Validation.java:299)

this is because WeakHashMap is not synchronized

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.