Skip to content

initial commit #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
target/
build/
.idea/
*.iml
.gradle
*.prefs
*.classpath
*.project
*.class
.DS_Store
76 changes: 76 additions & 0 deletions blackbox-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.avaje</groupId>
<artifactId>avaje-jsonb-parent</artifactId>
<version>1.5-SNAPSHOT</version>
</parent>

<artifactId>validator-blackbox-test</artifactId>
<name>validator blackbox test</name>
<description>test module</description>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<java.release>17</java.release>
</properties>

<dependencies>

<!-- for testing fields with third party annotations -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>

<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-jsonb</artifactId>
<version>1.5-SNAPSHOT</version>
</dependency>

<!-- <dependency>-->
<!-- <groupId>io.avaje</groupId>-->
<!-- <artifactId>avaje-jsonb-jackson</artifactId>-->
<!-- <version>0.15-SNAPSHOT</version>-->
<!-- </dependency>-->

<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-jsonb-generator</artifactId>
<version>1.5-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!-- test dependencies -->

<dependency>
<groupId>io.avaje</groupId>
<artifactId>junit</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>

</dependencies>


<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.example.customer.customtype.CustomTypeComponent
51 changes: 51 additions & 0 deletions blackbox-test/src/test/resources/skip-value-test-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[
{
"id": 1,
"name": "n0",
"skip_string": "234"
},
{
"id": 2,
"name": "n1",
"skip_int": 139
},
{
"id": 3,
"name": "n2",
"skip_dec": 895.34
},
{
"id": 4,
"node_id": "MDEwOlJlcG9zaXRvcnkxNTc2MDI1Mw==",
"name": "n3",
"skip_object": {
"id": 208973,
"node_id": "MDQ6VXNlcjIwODk3Mw=="
}
},
{
"id": 5,
"name": "n4",
"skip_array": [1,2,3,4]
},
{
"id": 6,
"name": "n5",
"skip_null": null
},
{
"id": 7,
"name": "n6",
"skip_true": true
},
{
"id": 8,
"name": "n7",
"skip_false": false
},
{
"id": 9,
"skip_string": "234",
"name": "n8"
}
]
48 changes: 48 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.avaje</groupId>
<artifactId>java11-oss</artifactId>
<version>3.9</version>
</parent>

<groupId>io.avaje</groupId>
<artifactId>avaje-validator-parent</artifactId>
<version>1.5-SNAPSHOT</version>

<packaging>pom</packaging>
<name>validator parent</name>
<description>parent pom for validator</description>

<scm>
<connection>scm:git:[email protected]:avaje/avaje-validator.git</connection>
<developerConnection>scm:git:[email protected]:avaje/avaje-validator.git</developerConnection>
<tag>avaje-validator-parent-1.1</tag>
</scm>

<properties>
<surefire.useModulePath>false</surefire.useModulePath>
<nexus.staging.autoReleaseAfterClose>true</nexus.staging.autoReleaseAfterClose>
</properties>

<modules>
<module>validator</module>
</modules>

<profiles>
<profile>
<id>central</id>
</profile>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>blackbox-test</module>
</modules>
</profile>
</profiles>

</project>
39 changes: 39 additions & 0 deletions validator/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.avaje</groupId>
<artifactId>avaje-validator-parent</artifactId>
<version>1.5-SNAPSHOT</version>
</parent>

<artifactId>avaje-validator</artifactId>
<name>validator</name>

<dependencies>

<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-inject</artifactId>
<version>9.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>


<dependency>
<groupId>io.avaje</groupId>
<artifactId>junit</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>

</dependencies>

</project>
56 changes: 56 additions & 0 deletions validator/src/main/java/io/avaje/validation/ValidPojo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.avaje.validation;

import static java.lang.annotation.RetentionPolicy.CLASS;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

/**
* Marks a type for JSON support.
*
* <h3>Examples:</h3>
*
* <pre>{@code
*
* @ValidPojo(naming = LowerHyphen)
* public class Customer ...
*
* }</pre>
*
* <pre>{@code
*
* @ValidPojo
* public record Product( ... )
*
* }</pre>
*/
@Retention(CLASS)
@Target(ElementType.TYPE)
public @interface ValidPojo {

/**
* Specify types to generate JsonAdapters for.
* <p>
* These types are typically in an external project / dependency or otherwise
* types that we can't or don't want to explicitly annotate with {@code @ValidPojo}.
* <p>
* Typically, we put this annotation on a package.
*
* <pre>{@code
*
* @ValidPojo.Import({Customer.class, Product.class, ...})
* package org.example.processor;
*
* }</pre>
*/
@Retention(CLASS)
@Target({ElementType.TYPE, ElementType.PACKAGE})
@interface Import {

/**
* Specify types to generate ValidPojo Adapters for.
*/
Class<?>[] value();
}
}
39 changes: 39 additions & 0 deletions validator/src/main/java/io/avaje/validation/ValidationAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2014 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.avaje.validation;

import java.lang.reflect.Type;
import java.util.Set;

import io.avaje.validation.stream.ConstraintViolation;

/** The core API for serialization to and from json. */
public interface ValidationAdapter<T> {

/** */
void validate(T value, Set<ConstraintViolation> violations);

/** Factory for creating a ValidationAdapter. */
public interface Factory {

/**
* Create and return a ValidationAdapter given the type and annotations or return null.
*
* <p>Returning null means that the adapter could be created by another factory.
*/
ValidationAdapter<?> create(Type type, Validator jsonb);
}
}
13 changes: 13 additions & 0 deletions validator/src/main/java/io/avaje/validation/ValidationType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.avaje.validation;

import java.util.Set;

import io.avaje.validation.stream.ConstraintViolation;


public interface ValidationType<T> {

Set<ConstraintViolation> validate(T object);

void validate(T object, Set<ConstraintViolation> violations);
}
Loading