Skip to content

Commit 885cf6e

Browse files
committed
Added example for streaming json validation
1 parent 50ca82b commit 885cf6e

20 files changed

+5337
-0
lines changed

README.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ A repository containing different java tutorials
4141

4242
## Serialization & Deserialization ☢️
4343
- [Two-way object serialization while using one model with Jackson and Spring Boot](two-way-object-serialization)
44+
- [Streaming JSON validation](streaming-json-validation)
4445

4546
## Miscellaneous 🎭
4647
- [JVM Rainbow - Mixing Java, Kotlin, Scala and Groovy](jvm-rainbow)

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<module>bypassing-overruling-ssl-configuration</module>
2727
<module>trust-me</module>
2828
<module>jvm-rainbow</module>
29+
<module>streaming-json-validation</module>
2930
</modules>
3031

3132
<licenses>
@@ -92,6 +93,8 @@
9293
<version.quarkus>3.13.0</version.quarkus>
9394
<version.mysql-connector>8.3.0</version.mysql-connector>
9495
<version.lombok>1.18.34</version.lombok>
96+
<version.jakarta-annotation-api>3.0.0</version.jakarta-annotation-api>
97+
<version.hibernate-validator>9.0.1.Final</version.hibernate-validator>
9598
<version.jboss-logging>3.6.0.Final</version.jboss-logging>
9699
<version.assertj-core>3.23.1</version.assertj-core>
97100
<version.junit>5.10.3</version.junit>

streaming-json-validation/pom.xml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>io.github.hakky54</groupId>
9+
<artifactId>java-tutorials</artifactId>
10+
<version>1.0.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>streaming-json-validation</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>com.fasterxml.jackson.core</groupId>
18+
<artifactId>jackson-databind</artifactId>
19+
<version>${version.jackson}</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.hibernate.validator</groupId>
23+
<artifactId>hibernate-validator</artifactId>
24+
<version>${version.hibernate-validator}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>jakarta.annotation</groupId>
28+
<artifactId>jakarta.annotation-api</artifactId>
29+
<version>${version.jakarta-annotation-api}</version>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.assertj</groupId>
34+
<artifactId>assertj-core</artifactId>
35+
<version>${version.assertj-core}</version>
36+
<scope>test</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.junit.jupiter</groupId>
40+
<artifactId>junit-jupiter-api</artifactId>
41+
<version>${version.junit}</version>
42+
<scope>test</scope>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.junit.jupiter</groupId>
46+
<artifactId>junit-jupiter-engine</artifactId>
47+
<version>${version.junit}</version>
48+
<scope>test</scope>
49+
</dependency>
50+
</dependencies>
51+
52+
</project>
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright 2022 Thunderberry.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package nl.altindag.validation.model;
18+
19+
import java.util.HashMap;
20+
import java.util.LinkedHashMap;
21+
import java.util.Map;
22+
import jakarta.annotation.Generated;
23+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
24+
import com.fasterxml.jackson.annotation.JsonAnySetter;
25+
import com.fasterxml.jackson.annotation.JsonCreator;
26+
import com.fasterxml.jackson.annotation.JsonIgnore;
27+
import com.fasterxml.jackson.annotation.JsonInclude;
28+
import com.fasterxml.jackson.annotation.JsonProperty;
29+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
30+
import com.fasterxml.jackson.annotation.JsonValue;
31+
import jakarta.validation.Valid;
32+
33+
@JsonInclude(JsonInclude.Include.NON_NULL)
34+
@JsonPropertyOrder({
35+
"status"
36+
})
37+
@Generated("jsonschema2pojo")
38+
public class AdvancedSecurity {
39+
40+
@JsonProperty("status")
41+
private AdvancedSecurity.Status status;
42+
@JsonIgnore
43+
@Valid
44+
private Map<String, Object> additionalProperties = new LinkedHashMap<String, Object>();
45+
46+
/**
47+
* No args constructor for use in serialization
48+
*
49+
*/
50+
public AdvancedSecurity() {
51+
}
52+
53+
public AdvancedSecurity(Status status) {
54+
super();
55+
this.status = status;
56+
}
57+
58+
@JsonProperty("status")
59+
public AdvancedSecurity.Status getStatus() {
60+
return status;
61+
}
62+
63+
@JsonProperty("status")
64+
public void setStatus(Status status) {
65+
this.status = status;
66+
}
67+
68+
@JsonAnyGetter
69+
public Map<String, Object> getAdditionalProperties() {
70+
return this.additionalProperties;
71+
}
72+
73+
@JsonAnySetter
74+
public void setAdditionalProperty(String name, Object value) {
75+
this.additionalProperties.put(name, value);
76+
}
77+
78+
@Generated("jsonschema2pojo")
79+
public enum Status {
80+
81+
ENABLED("enabled"),
82+
DISABLED("disabled");
83+
private final String value;
84+
private final static Map<String, Status> CONSTANTS = new HashMap<String, Status>();
85+
86+
static {
87+
for (Status c: values()) {
88+
CONSTANTS.put(c.value, c);
89+
}
90+
}
91+
92+
Status(String value) {
93+
this.value = value;
94+
}
95+
96+
@Override
97+
public String toString() {
98+
return this.value;
99+
}
100+
101+
@JsonValue
102+
public String value() {
103+
return this.value;
104+
}
105+
106+
@JsonCreator
107+
public static AdvancedSecurity.Status fromValue(String value) {
108+
Status constant = CONSTANTS.get(value);
109+
if (constant == null) {
110+
throw new IllegalArgumentException(value);
111+
} else {
112+
return constant;
113+
}
114+
}
115+
116+
}
117+
118+
}

0 commit comments

Comments
 (0)