Skip to content

Commit a0efd94

Browse files
authored
Merge pull request eugenp#3005 from earth001/master
Update for article BAEL-1121
2 parents 3bb538a + a60d922 commit a0efd94

7 files changed

Lines changed: 423 additions & 38 deletions

File tree

‎jsonb/.gitignore‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#folders#
2+
.idea
3+
/target
4+
/neoDb*
5+
/data
6+
/src/main/webapp/WEB-INF/classes
7+
*/META-INF/*
8+
9+
# Packaged files #
10+
*.jar
11+
*.war
12+
*.ear

‎jsonb/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## JSON B

‎jsonb/pom.xml‎

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.baeldung</groupId>
7+
<artifactId>json-b</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>json-b</name>
12+
<description>json-b sample project</description>
13+
<profiles>
14+
<profile>
15+
<id>yasson</id>
16+
<activation>
17+
<activeByDefault>true</activeByDefault>
18+
</activation>
19+
<dependencies>
20+
<!-- Dependencies for Yasson -->
21+
<dependency>
22+
<groupId>org.eclipse</groupId>
23+
<artifactId>yasson</artifactId>
24+
<version>${yasson.version}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.glassfish</groupId>
28+
<artifactId>javax.json</artifactId>
29+
<version>${javax.json.version}</version>
30+
</dependency>
31+
</dependencies>
32+
</profile>
33+
<profile>
34+
<id>johnzon</id>
35+
<dependencies>
36+
<!-- Dependencies for Johnzon -->
37+
<dependency>
38+
<groupId>org.apache.geronimo.specs</groupId>
39+
<artifactId>geronimo-json_1.1_spec</artifactId>
40+
<version>${geronimo-json_1.1_spec.version}</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.apache.johnzon</groupId>
44+
<artifactId>johnzon-jsonb</artifactId>
45+
<version>${johnzon.version}</version>
46+
</dependency>
47+
</dependencies>
48+
</profile>
49+
</profiles>
50+
<dependencies>
51+
<dependency>
52+
<groupId>javax.json.bind</groupId>
53+
<artifactId>javax.json.bind-api</artifactId>
54+
<version>${jsonb-api.version}</version>
55+
</dependency>
56+
<!-- utils -->
57+
<dependency>
58+
<groupId>org.apache.commons</groupId>
59+
<artifactId>commons-collections4</artifactId>
60+
<version>${commons-collections4.version}</version>
61+
<scope>test</scope>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>org.junit.jupiter</groupId>
66+
<artifactId>junit-jupiter-api</artifactId>
67+
<version>${junit.jupiter.version}</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.junit.jupiter</groupId>
71+
<artifactId>junit-jupiter-engine</artifactId>
72+
<version>${junit.jupiter.version}</version>
73+
<scope>test</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>org.junit.platform</groupId>
77+
<artifactId>junit-platform-surefire-provider</artifactId>
78+
<version>${junit.platform.version}</version>
79+
<scope>test</scope>
80+
</dependency>
81+
<dependency>
82+
<groupId>org.junit.platform</groupId>
83+
<artifactId>junit-platform-runner</artifactId>
84+
<version>${junit.platform.version}</version>
85+
<scope>test</scope>
86+
</dependency>
87+
88+
</dependencies>
89+
90+
<properties>
91+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
92+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
93+
<maven.compiler.source>1.8</maven.compiler.source>
94+
<maven.compiler.target>1.8</maven.compiler.target>
95+
<junit.platform.version>1.0.0</junit.platform.version>
96+
<junit.jupiter.version>5.0.0</junit.jupiter.version>
97+
<maven-surefire-plugin.version>2.20</maven-surefire-plugin.version>
98+
<jsonb-api.version>1.0</jsonb-api.version>
99+
<johnzon.version>1.1.3</johnzon.version>
100+
<geronimo-json_1.1_spec.version>1.0</geronimo-json_1.1_spec.version>
101+
<yasson.version>1.0</yasson.version>
102+
<javax.json.version>1.1.2</javax.json.version>
103+
<commons-collections4.version>4.1</commons-collections4.version>
104+
</properties>
105+
106+
</project>
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package com.baeldung.jsonb;
2+
3+
import java.math.BigDecimal;
4+
import java.time.LocalDate;
5+
6+
import javax.json.bind.annotation.JsonbDateFormat;
7+
import javax.json.bind.annotation.JsonbNumberFormat;
8+
import javax.json.bind.annotation.JsonbProperty;
9+
import javax.json.bind.annotation.JsonbTransient;
10+
11+
public class Person {
12+
13+
private int id;
14+
@JsonbProperty("person-name")
15+
private String name;
16+
@JsonbProperty(nillable = true)
17+
private String email;
18+
@JsonbTransient
19+
private int age;
20+
@JsonbDateFormat("dd-MM-yyyy")
21+
private LocalDate registeredDate;
22+
private BigDecimal salary;
23+
24+
public Person() {
25+
}
26+
27+
public Person(int id, String name, String email, int age, LocalDate registeredDate, BigDecimal salary) {
28+
super();
29+
this.id = id;
30+
this.name = name;
31+
this.email = email;
32+
this.age = age;
33+
this.registeredDate = registeredDate;
34+
this.salary = salary;
35+
}
36+
37+
public int getId() {
38+
return id;
39+
}
40+
41+
public void setId(int id) {
42+
this.id = id;
43+
}
44+
45+
public int getAge() {
46+
return age;
47+
}
48+
49+
public void setAge(int age) {
50+
this.age = age;
51+
}
52+
53+
public String getEmail() {
54+
return email;
55+
}
56+
57+
public void setEmail(String email) {
58+
this.email = email;
59+
}
60+
61+
public String getName() {
62+
return name;
63+
}
64+
65+
public void setName(String name) {
66+
this.name = name;
67+
}
68+
69+
@JsonbNumberFormat(locale = "en_US", value = "#0.0")
70+
public BigDecimal getSalary() {
71+
return salary;
72+
}
73+
74+
public void setSalary(BigDecimal salary) {
75+
this.salary = salary;
76+
}
77+
78+
public LocalDate getRegisteredDate() {
79+
return registeredDate;
80+
}
81+
82+
public void setRegisteredDate(LocalDate registeredDate) {
83+
this.registeredDate = registeredDate;
84+
}
85+
86+
@Override
87+
public String toString() {
88+
StringBuilder builder = new StringBuilder();
89+
builder.append("Person [id=");
90+
builder.append(id);
91+
builder.append(", name=");
92+
builder.append(name);
93+
builder.append(", email=");
94+
builder.append(email);
95+
builder.append(", age=");
96+
builder.append(age);
97+
builder.append(", registeredDate=");
98+
builder.append(registeredDate);
99+
builder.append(", salary=");
100+
builder.append(salary);
101+
builder.append("]");
102+
return builder.toString();
103+
}
104+
105+
@Override
106+
public int hashCode() {
107+
final int prime = 31;
108+
int result = 1;
109+
result = prime * result + id;
110+
return result;
111+
}
112+
113+
@Override
114+
public boolean equals(Object obj) {
115+
if (this == obj)
116+
return true;
117+
if (obj == null)
118+
return false;
119+
if (getClass() != obj.getClass())
120+
return false;
121+
Person other = (Person) obj;
122+
if (id != other.id)
123+
return false;
124+
return true;
125+
}
126+
127+
}

0 commit comments

Comments
 (0)